开发者

"ERROR: broken data stream when reading image file" (TrueType fonts libjpeg and PIL on OS X)

I'm running OS X 10.6.7, Python 2.6, and writing a small wxPython application that uses PIL to manipulate an image and add some text to it.

After quite a bit of configuration woes with attempting to get PIL running with libjpeg and PIL, I followed the instructions at this site.

Upon running python setup.py build_ext -i (from inside the Imaging-1.1.7 folder) I get:

--------------------------------------------------------------------
PIL 1.开发者_StackOverflow中文版1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      darwin 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
          [GCC 4.2.1 (Apple Inc. build 5646)]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available
--------------------------------------------------------------------

Additionally, running python selftest.py in the Imaging-1.1.7 install folder, I get:

--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY 
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from ./PIL
--------------------------------------------------------------------
--- PIL CORE support ok
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
--- LITTLECMS support ok
--------------------------------------------------------------------
Running selftest:
--- 57 tests passed.

However, when rendering my first PIL image in my own code, I still get:

File "/Library/Python/2.6/site-packages/PIL/Image.py", line 1290, in resize self.load()
File "/Library/Python/2.6/site-packages/PIL/ImageFile.py", line 215, in load raise_ioerror(e)
File "/Library/Python/2.6/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'm kind of at a loss as to what to try next. Any ideas? The code that is causing this crash seems to be:

try:
    self.img = self.img.resize((self.screenwidth, self.screenheight), 
            Image.ANTIALIAS)
    except IOError, e:
        print "Error resizing: " + str(e)
        self.img = self.img.resize((self.screenwidth, self.screenheight))
        raise 


You should consider uninstalling PIL and following the instructions on this website - http://jetfar.com/libjpeg-and-python-imaging-pil-on-snow-leopard/

In particular, it appears that you want to make sure that libjpeg is at version 6b, not 8c (see below)


I am able to reproduce this with Mac OS X 10.5 using macports

This is related to a another question: How to solve IOError:broken data stream when reading image file?

The answer there indicates that the bug might have something to do with libjpeg

As far as I can tell, the error appears to be caused by a forward incompatibility with libjpeg v8c.

I cannot determine what is causing this exactly; all I can say is that on a variety of other systems I use that aren't exhibiting this behavior error (OS X 10.5 with fink, Redhat 5.2, Ubuntu 11.10 and 10.10), they all use libjpeg 6b. Only macports uses 8c, and macports is the only system where I am getting this error.


I was able to use PIL with the homebrew package manager.


I've got a similar error when reading .jpg file with an up-to-date Python environment and Sierra Mac OS. I've found a quick workaround which consists to convert all the .jpg files to .png files Hoping that can help someone else.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜