[Tutor] PIL and converting an image to and from a string value
chare at labr.net
Fri Apr 27 17:53:20 CEST 2012
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!
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
More information about the Tutor