Python Image Library

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • S. D. Rose

    #1

    Python Image Library

    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.

    My steps are here:
    [color=blue][color=green][color=darkred]
    >>> import MySQLdb
    >>> import array, cStringIO
    >>> import Image, ImageOps[/color][/color][/color]
    [color=blue][color=green][color=darkred]
    >>> con = MySQLdb(db='', host='', user='', passwd='')
    >>> cur = con.cursor()
    >>> cur.execute('SE LECT photo FROM photos')
    >>> result = cur.fetchone()
    >>> photo = result[0].tostring()[/color][/color][/color]
    [color=blue][color=green][color=darkred]
    >>> colorImg = Image.open(cStr ingIO.StringIO( photo))
    >>> colorImg.show() # Shows a color image on the Win32 screen[/color][/color][/color]
    [color=blue][color=green][color=darkred]
    >>> img.format[/color][/color][/color]
    'JPEG'
    [color=blue][color=green][color=darkred]
    >>> bwImg =imageOps.grays cale(img)
    >>> bwImg.format[/color][/color][/color]
    [color=blue][color=green][color=darkred]
    >>> todb = bwImg.tostring( encoder_name='J PEG')[/color][/color][/color]
    TRACEBACK ...
    IOError: encoder JPEG not available.[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    Any help telling me how to take the bwImg image (not the PIL object) and
    placing it back into a MySQL database would be highly appreciated!

    Thanks!
    Dave



Working...