#!/usr/bin/env python
import Image
import ImageDraw
import StringIO
import sys
import cgi
import cgitb
cgitb.enable()

DEFAULT_r=100

params=cgi.FieldStorage()
if 'r' in params:
    try:
        r=int(params['r'].value)
    except ValueError:
        r=DEFAULT_r
else:
    r=DEFAULT_r

img=Image.new("RGB",(200,200))
draw=ImageDraw.Draw(img)
draw.ellipse([(100-r,100-r),(100+r,100+r)],fill=(64,64,128),outline=(128,128,128))

tmp=StringIO.StringIO()
img.save(tmp,"PNG")
tmp.seek(0)
strimg=tmp.read()

sys.stdout.write("Content-type: image.png\r\n")
sys.stdout.write("Content-length: %d\r\n" % len(strimg))
sys.stdout.write("\r\n")
sys.stdout.write(strimg)

