How to solve IOError:broken data stream when reading image file?

风格不统一 提交于 2019-12-08 17:13:27

问题


Im working under Ubuntu 11.04. I'm trying to work with PIL in my Django project. Sadly PIL cannot load my image.

Here is the PIL setup summary:

PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
              [GCC 4.5.2]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available
--------------------------------------------------------------------

I tried coding in python shell and it returns the error when I called load() function:

>>> import PIL
>>> import Image
>>> import _imaging
>>> i = Image.open("someimage.jpg")
>>> i
<JpegImagePlugin.JpegImageFile image mode=RGB size=600x599 at 0x9646C0C>
>>> i.load()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/joseph/Desktop/thesis/env/lib/python2.7/site-packages/PIL/ImageFile.py", line 215, in load
raise_ioerror(e)
File "/home/joseph/Desktop/thesis/env/lib/python2.7/site-packages/PIL/ImageFile.py", line 52, in raise_ioerror
raise IOError(message + " when reading image file")
IOError: broken data stream when reading image file

I am also working in a Virtual Environment, I am having problems with uploading jpeg image on my Django project. PNG works fine but it rejects JPEG


回答1:


sudo apt-get install libjpeg8-dev

rebuild PIL and install again.




回答2:


I had the same problem, but unfortunately we were using RHEL which only had libjpeg 6b.

Digging into this problem further, this error seems to occur when you are using a JPEG feature that isn't supported in the version of libjpeg you're using. In my case it was arithmetic encoding (introduced in version 7).

I found the wikipedia page on libjpeg to be helpful in determining which types of JPEG files could be opened by which versions. so...

TL;DR

Upgrade libjpeg if you can or re-save your images as baseline JPEG's.




回答3:


Use Pillow and report issues as they occur and the Pillow team will fix them. Bonus points for submitting a pull request along with your issue report. Also see: https://stackoverflow.com/a/7770547/185820



来源:https://stackoverflow.com/questions/7652249/how-to-solve-ioerrorbroken-data-stream-when-reading-image-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!