[Image-SIG] PIL and converting an image to and from a string value

Chris Hare chare at labr.net
Fri Apr 27 16:35:44 CEST 2012

okay - I have an error but I don't understand what I got wrong:

self.imageBuffer = StringIO.StringIO()
image = Image.open(filename)

image = image.resize((150,150),Image.ANTIALIAS)
image.save(self.imageBuffer, format= 'PNG')

image = Image.open(self.imageBuffer)

IOError: cannot identify image file

The error occurs when trying to open the imageBuffer so I can work with the data in the buffer.  What have I missed?

On Apr 27, 2012, at 8:21 AM, Charles Cazabon wrote:

> Chris Hare <Chare at labr.net> wrote:
>> I am stuck however, in figuring out how to take the string data and
>> converting it back to an image that I can put into the canvas widget.
> See the PIL handbook, where it says "If you have an entire image file in a
> string, wrap it in a StringIO object, and use open to load it."
> Charles
> -- 
> ------------------------------------------------------------------
> Charles Cazabon                   <charlesc-pyimagesig at pyropus.ca>
> Software, consulting, and services available at http://pyropus.ca/
> ------------------------------------------------------------------
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig

More information about the Image-SIG mailing list