[Tutor] PIL and converting an image to and from a string value
chare at labr.net
Sat Apr 28 15:13:11 CEST 2012
What I did:
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)
So, that is how I got around the problem
On Apr 27, 2012, at 1:22 PM, Russell Smith wrote:
> What did you do?
> On Friday, April 27, 2012, Chris Hare wrote:
> I got it figured out.
> On Apr 27, 2012, at 12:21 AM, Chris Hare wrote:
> > Here is what I am trying to:
> > the application user chooses an image file. I want to store the image data in a field in a sqlite database. My understanding from the reading I have done is that I have to convert the image data into a string , which I can then store in the database. Additionally, I need to be able to take the stored image data and convert it back to an image so I can display it in a canvas widget. I am using the python imaging library
> > I think I have the following parts correct:
> > image = Image.open("cover.jpg")
> > image = image.resize((150,150),Image.ANTIALIAS)
> > png = image.tostring("PNG")
> > I am taking the image data from the file, resizing the image, and then using the PNG coder to force it into a PNG format image and converting it to a string.
> > 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. Either I am not finding a good explanation of how to do this or I am just not understanding what I am finding:-)
> > Any ideas are appreciated!
> > Thanks,
> > Chris
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor