[Tutor] PIL and converting an image to and from a string value

Russell Smith savtech138 at gmail.com
Fri Apr 27 20:22:22 CEST 2012


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 <javascript:;>
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org <javascript:;>
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120427/9ffada40/attachment-0001.html>


More information about the Tutor mailing list