Are you sure that 'bitmaps/image.png' is not an invalid image file?

I damaged a PNG file and got this result while trying to .tostring() it:

>>> img = Image.open("broken.png")
>>> img = img.tostring()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/site-packages/PIL/Image.py", line 436, in tostring
    import tempfile
  File "/usr/lib/python2.3/site-packages/PIL/ImageFile.py", line 192, in load
    raise IOError("image file is truncated (%d bytes not processed)" % len(b))
IOError: unknown error when reading image file

Image.open() does not fully load the image, it just looks at headers to
find such information as the resolution of the image.  The full image is
loaded when .load() is called explicitly, or some other method is called
that requires the image be loaded.  Therefore, it is no surprise that a
damaged image might open() but give an exception later the first time
the image data is used.

Jeff

Attachment: pgpSoWjPFLLRd.pgp
Description: PGP signature

_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to