Ok, here is a working block of code based on yours: #!/usr/bin/env python #--------------------------------------------------------- import StringIO, cgi, os, sys, string, Image im = Image.open('backgroundimage.gif') # here I'll be drawing all over my image... # Now I want to send it to a browser... sfp = StringIO.StringIO() im.save(sfp,'gif') print 'Content-Type: image/gif\n' sys.stdout.write(sfp.getvalue()) #--------------------------------------------------------- Andrew was right on the money regarding the print statement and the extra \n it adds. I generally do it like this, though, *depending* on that extra newline. On my Apache server under Python 1.5.2, this works great. I didn't need the \r's either. Incidentally, here is a suggestion: #!/usr/bin/env python #--------------------------------------------------------- import sys sys.stderr = sys.stdout sys.stdin.close() try: import StringIO, cgi, os, string, Image im = Image.open('backgroundimage.gif') # here I'll be drawing all over my image... # Now I want to send it to a browser... sfp = StringIO.StringIO() im.save(sfp,'gif') print 'Content-Type: image/gif\n' sys.stdout.write(sfp.getvalue()) except: print 'Content-Type: text/plain\n' import traceback traceback.print_exc(file=sys.stdout) #--------------------------------------------------------- If you have problems, you just point your browser directly at the CGI script and you get readable error messages!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4