我正在运行 OS X 10.6.7、Python 2.6,并编写了一个小型 wxPython 应用程序,该应用程序使用 PIL 来操作图像并向其添加一些文本。
在尝试使用 libjpeg 和 PIL 运行 PIL 进行了相当多的配置问题之后,我按照此站点上的说明进行操作。
运行后python setup.py build_ext -i
(从 Imaging-1.1.7 文件夹中)我得到:
--------------------------------------------------------------------
PIL 1.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
--------------------------------------------------------------------
此外,python selftest.py
在 Imaging-1.1.7 安装文件夹中运行,我得到:
--------------------------------------------------------------------
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.
但是,在我自己的代码中渲染我的第一个 PIL 图像时,我仍然得到:
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
我有点不知道接下来要尝试什么。有任何想法吗?导致此崩溃的代码似乎是:
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