我正在尝试加载我的 .jpg 文件,但它引发了错误,但如果我再试一次,就没问题了!为什么??
我的代码和错误:
>>> 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>
>>>
谢谢!
最佳答案
我遇到了同样的问题并想出了一个解决方案,我在这里讨论:https://stackoverflow.com/a/23575424/3622198 .
在代码块之前的某处,只需添加以下内容:
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
...你应该可以开始了!
编辑:看起来这有助于与 Pillow 捆绑在一起的 PIL 版本(“pip install pillow”),但可能不适用于 PIL 的默认安装
关于Python PIL,图像。 image.load() 后出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9211719/