2012-04-11 40 views
0

我曾嘗試http://mail.python.org/pipermail/image-sig/2010-June/006313.html,但我得到一個錯誤仍然的Python 2.7 PIL打開JPEG格式錯誤的圖片,蘋果獅子

[email protected]:~/hub/lweibo$ python2.7 lweibo.py 
Traceback (most recent call last): 
    File "lweibo.py", line 235, in <module> 
    lweibo_render(107906) 
    File "lweibo.py", line 228, in lweibo_render 
    p = LPic(a_body, a_title, a_ukey_nickname, a_ukey_img, a_create) 
    File "lweibo.py", line 114, in __init__ 
    a_ukey_img.save("s.png", "PNG", qualty=100) 
    File "/Users/dreampuf/opt/macports/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Pillow-1.7.7-py2.7-macosx-10.7-x86_64.egg/PIL/Image.py", line 1406, in save 
    self.load() 
    File "/Users/dreampuf/opt/macports/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Pillow-1.7.7-py2.7-macosx-10.7-x86_64.egg/PIL/ImageFile.py", line 215, in load 
    raise_ioerror(e) 
    File "/Users/dreampuf/opt/macports/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Pillow-1.7.7-py2.7-macosx-10.7-x86_64.egg/PIL/ImageFile.py", line 52, in raise_ioerror 
    raise IOError(message + " when reading image file") 
IOError: broken data stream when reading image file 

然後我嘗試使用的MacPorts安裝jpeg6b,但它提醒我, jpeg6b太老版本,並重新命名爲jpeg

[email protected]:~/lweibo$ sudo port install jpeg6b 
Password: 
---> Configuring jpeg6b 
Error: jpeg6b has been renamed to jpeg. Please install jpeg instead. 
Error: Target org.macports.configure returned: obsolete port 
Log for jpeg6b is at: /Users/dreampuf/opt/macports/var/macports/logs/_Users_dreampuf_opt_macports_var_macports_sources_rsync.macports.org_release_tarballs_ports_graphics_jpeg6b/jpeg6b/main.log 
Error: Status 1 encountered during processing. 
To report a bug, see <http://guide.macports.org/#project.tickets> 

但jpeg的版本是8d。

[email protected]:~/hub/lweibo$ port installed jpeg 
The following ports are currently installed: 
    jpeg @8d_0 (active) 

我知道是什麼原因導致此錯誤。但我不能在我的系統中安裝jpeg6b,或無法重新安裝PIL以使用jpeg6b

回答

0

我不明白你的第一個例子寫出一個PNG,然後談論JPEG問題之間的相關性。

如果你是依靠macports爲你的libjpeg,那麼爲什麼不用它來安裝PIL呢?
當建立PIL你可以告訴它到哪裏尋找的JPEG庫: export JPEG_ROOT=/usr/local/include

我會建議刪除PIL,除去libjpeg的...然後重新安裝最新的JPEG,然後重建PIL。使用PIP安裝PIL

嘗試:pip install -U PIL

+0

我的意思是我使用JPG格式的圖片粘貼到PNG的圖片。 – Dreampuf 2012-04-11 03:48:59

+0

我使用'export JPEG_ROOT =/usr/local/lib'(我的jpeg6b實際路徑),它仍然是錯誤的。 – Dreampuf 2012-04-11 04:06:19

+0

實際嘗試它與它指向'include'而不是'lib'? – jdi 2012-04-11 04:11:59