Dynamic image creation for the web...
Tompa
tompa1969 at yahoo.com
Sun Aug 28 15:57:27 EDT 2005
Benjamin Niemann <pink <at> odahoda.de> writes:
> You are almost there.
I don't feel so...
> Your create_image.py does not return anything to the
> browser yet.
Yes, I am aware of that but I do not what to return.
> First return proper HTTP headers, e.g.
>
> sys.stdout.write('Status: 200 OK\r\n')
> sys.stdout.write('Content-type: image/gif\r\n')
> sys.stdout.write('\r\n')
Ok, but if possible I'd rather not return anything HTTP/HTML-related from my
create_image.py file.
> Then check the PIL docs to find out, how to output the image to sys.stdout
> (instead of writing to a file).
>
Ok, then I get this:
from PIL import Image, ImageDraw
import sys
im = Image.new("P", (600, 400))
draw = ImageDraw.Draw(im)
draw.rectangle((0, 0) + im.size, fill="blue")
sys.stdout.write('Status: 200 OK\r\n')
sys.stdout.write('Content-type: image/gif\r\n')
sys.stdout.write('\r\n')
im.save(sys.stdout, "GIF")
But this does not work.
I also tested to skip the HTTP-header stuff and just write the gif to
sys.stdout, believing that that would work. But not so...
Hmm, I'm a newbie to Python (as you already probably have noticed ;-) so I
don't know what else I should try. Any hints are welcome!
/Tompa
More information about the Python-list
mailing list