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

Gareth Rees gdr at garethrees.org
Fri Apr 27 16:55:53 CEST 2012

Chris Hare wrote:
> 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?

You need to rewind to the start of the buffer before trying to read from it:


Gareth Rees

More information about the Image-SIG mailing list