开发者

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

开发者 https://www.devze.com 2023-04-10 21:48 出处:网络
Im working under Ubuntu 11.04. I\'mtrying to work with PIL in my Django project. Sadly PIL cannot load my image.

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


sudo apt-get install libjpeg8-dev

rebuild PIL and install again.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消