[Image-SIG] Unable to load dynamic image into browser

Marshintprop JMarsh at marshintprop.com
Mon Dec 24 21:35:28 CET 2012

I do not seem to have success in generating a dynamic image into Internet
Explorer through CGI.  If I save the file and then load it, it works but
when I try to keep the generated image dynamic.  I am using Python 2.6.5 and
the corresponding PIL library.


f = cStringIO.StringIO()

img.save(f, "PNG")


print "Content-type: image/png\n"


print f.read()


The above will just generate a screen filled with ascii characters and
symbols.  I have also tried JPEG to no avail.


Below generates a blank image:


sys.stdout.write('Status: 200 OK\r\n')

sys.stdout.write('Content-type: image/png\r\n\n')

sys.stdout.write('%s' % f.getvalue())



Can someone point out my error here?  Writing to file in a cgi environment
is not a great thing to be doing.  Img.sav('test.png') is valid.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20121224/eb59b19c/attachment-0001.html>

More information about the Image-SIG mailing list