[Tutor] problem in converting pixel data to image file

Ashish Sethi ashishbitsgoa at gmail.com
Mon Aug 18 11:00:08 CEST 2008

Hi all,
I have a problem in converting the pixel data (read from a string and
written to a file using fromstring command in PIL ).
The file handle of this file is called buffer. Now, when I tried to open the
file as an image file but it didnt work.
Then I read the documentation of PIL and found this written about fromstring
"Note that this function decodes pixel data, not entire images. If you
have an entire image in a string, wrap it in a *StringIO *object, and use
*open *to load it."
so i wrote the following code....

file = StringIO.StringIO(buffer)
img = Image.open(file)
img.save(file, 'JPEG')

img = Image.open(file)
  File "/home/rahhal/python/lib/python2.4/site-packages/PIL/Image.py", line
1745, in open
    raise IOError("cannot identify image file")
IOError: cannot identify image file

Can any one please help in solving my problem??
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080818/e7a1c2bd/attachment.htm>

More information about the Tutor mailing list