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

Andrew Dalke dalke at acm.org
Tue Apr 3 17:57:45 EDT 2001


Gary Walker:
>Here's some actual code of mine that doesn't work:
>
>************************************
>#!/usr/bin/python
>
>import StringIO, cgi, os, sys, string, Image
>
>im = Image.open('backgroundimage.gif')

               add--> , "rb" <-- here ^^
to make it
im = Image.open('backgroundimage.gif', "rb")

else it won't work on MS Windows or Macs.

># 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\r\n\r\n'

Replace this with

sys.stdout.write("Content-Type: image/gif\r\n\r\n")

because print adds its own "\n" after it prints
the text.

>sys.stdout.write(sfp.getvalue())

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list