Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PIL, Image. Error after image.load()

I'm trying to load my .jpg file and it raises error, but if I try it again, it's ok! Why??

My code and error:

>>> import Image
>>> im1 = Image.open('/tmp/test.jpg')
>>> im1.load()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/PIL/ImageFile.py", line 201, in load
raise IOError("image file is truncated (%d bytes not processed)" % len(b))
IOError: image file is truncated (0 bytes not processed)
>>> im1.load()
<PixelAccess object at 0x7feffc2a1170>
>>>

Thank you!

like image 756
Hare Avatar asked Feb 09 '12 13:02

Hare


1 Answers

I had this same issue and came up with a solution which I discuss here: https://stackoverflow.com/a/23575424/3622198.

Somewhere before your code block, simply add the following:

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

... and you should be good to go!

EDIT: It looks like this helps for the version of PIL bundled with Pillow ("pip install pillow"), but may not work for default installations of PIL

like image 163
abhillman Avatar answered Nov 15 '22 08:11

abhillman