PIL: how to return a StringIO of an Image

Christoph NOSPAM at xyzxyzxyz.yy
Fri Nov 14 16:26:14 CET 2003


Hi,

I have a script I pass (from Zope) an image file to, to do some PIL image stuff 
with it. I want a StringIO instance representing the altered image file to be 
returned. What is the method to get the image data (header and pixel data)? I 
tried Image.tostring(), but that only returns the pixle data. But to be able to 
use the returned data in Zope as an image file (manage_addImage, in case someone 
cares), I need the complete representation of the. file.

Here’s some code:

def modify_image(self, my_image):
   from PIL import Image
   from StringIO import StringIO

   image=Image.open(my_image)
   . # do some PIL
   .
   .
   image.save('test', 'JPEG')
   image=StringIO(image.????()) # what's the right method?
   return image

Any hints? Thanx!
Regards
Christoph





More information about the Python-list mailing list