Re: PIL and converting an image to and from a string value

Gareth Rees <[email protected]> Fri, 27 Apr 2012 15:55:53 +0100
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
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:

	self.imageBuffer.seek(0)

-- 
Gareth Rees
_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig