[Image-SIG] Place image into MySQL db.

Fredrik Lundh fredrik at pythonware.com
Sun Dec 18 09:14:38 CET 2005

"S. D. Rose" wrote:

> I have a question about PIL.
> I get a 50k photo from a MySQL table, convert it to grey-scale, do some
> rotations, etc.  Then I want to put it back.  It seems that after I do the
> greyscale, it converts from 'JPEG' to 'RAW'.  Can anyone tell me how I
> convert the image back to 'JPEG' and then insert the photo into the MySQL
> database? I've tried .tostring('jpeg') but that told me it couldn't load the
> jpeg encoder.

"tostring" converts the pixel contents to a string buffer, much like array.tostring
and similar methods in the Python library.

if you want to save the image to an external file format, use the "save" method.
to save to a string, use a StringIO or cStringIO stream as the target:

    out = cStringIO.StringIO()
    im.save(out, "jpeg")
    data = out.getvalue()


More information about the Image-SIG mailing list