Movatterモバイル変換


[0]ホーム

URL:


Newbie has question that's not exactly Python...

Chris Gonnermanchris.gonnerman at usa.net
Tue Apr 3 23:45:35 EDT 2001


Ok, here is a working block of code based on yours:#!/usr/bin/env python#---------------------------------------------------------import StringIO, cgi, os, sys, string, Imageim = 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 statementand the extra \n it adds.  I generally do it like this,though, *depending* on that extra newline.  On my Apacheserver under Python 1.5.2, this works great.  I didn't needthe \r's either.Incidentally, here is a suggestion:#!/usr/bin/env python#---------------------------------------------------------import syssys.stderr = sys.stdoutsys.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 directlyat the CGI script and you get readable error messages!


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp