#!/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)
