File: gddemo.py

package info (click to toggle)
python-gd 0.26-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 216 kB
  • ctags: 103
  • sloc: ansic: 1,350; makefile: 64; python: 26
file content (37 lines) | stat: -rwxr-xr-x 807 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python

import sys
import gd

def simple(font):
    im = gd.image((200, 200))

    white = im.colorAllocate((255, 255, 255))
    black = im.colorAllocate((0, 0, 0))
    red = im.colorAllocate((255, 0, 0))
    blue = im.colorAllocate((0, 0, 255))

    im.colorTransparent(white)
    im.interlace(1)

    im.rectangle((0,0),(199,199),black)
    im.arc((100,100),(195,175),0,360,blue)
    im.fill((100,100),red)

    print im.get_bounding_rect(font, 12.0, 0.0, (10, 100), "Hello Python")

    im.string_ft(font, 12.0, 0.0, (10, 100), "Hello Python", black)

    f=open("xx.png","w")
    im.writePng(f)
    f.close()

    f=open("xx.jpg", "w")
    im.writeJpeg(f,100)
    f.close()

if len(sys.argv) >= 2:
    simple(sys.argv[1])
else:
    print 'usage:', sys.argv[0], 'font.ttf'
    sys.exit(1)