Python PIL,图像。 image.load() 后出错

标签 python python-imaging-library

我正在尝试加载我的 .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/

相关文章:

python - 如何使用 Kivy 获取 textinput 的值

python - 如何将 AxesImage 中的坐标映射到保存的图像文件中的坐标?

python - 在 Python 中,解析自定义 XML 标签而不解析 HTML

python - Selenium 没有将 key 发送到我的 gwt-SuggestBox

python - 为什么我的 _getexif() 返回 None?

python - PyTesseract 在表中没有看到一些个位数

python - 映射器功能,用于查找文本文件中的最小单词

python - Pillow 和 Numpy,获取像素值

python - 为什么 PIL/Pillow 裁剪不起作用?

png - 使用 Pillow 保存为 JPEG 的图像与原始图像不同。