在python

时间:2015-10-23 06:40:41

标签: python pillow webp

我编写了一个小程序,将 webp 转换为python中的jpg

import imghdr
from PIL import Image

im = Image.open("unnamed.webp").convert("RGB")
im.save("test.jpg","jpeg")

执行时会出现以下错误

No handlers could be found for logger "PIL.ImageFile"
Traceback (most recent call last):
  File "webptopng.py", line 3, in <module>
    im = Image.open("unnamed.webp").convert("RGB")
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 2286, in open
    % (filename if filename else fp))
IOError: cannot identify image file 'unnamed.webp'

我已经安装了具有webp功能的枕头。这是我的枕头安装输出

--------------------------------------------------------------------
PIL SETUP SUMMARY
--------------------------------------------------------------------
version      Pillow 3.0.0
platform     linux2 2.7.3 (default, Jun 22 2015, 19:33:41)
             [GCC 4.6.3]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
*** OPENJPEG (JPEG2000) support not available
--- ZLIB (PNG/ZIP) support available
*** LIBTIFF support not available
--- FREETYPE2 support available
*** LITTLECMS2 support not available
--- WEBP support available
*** WEBPMUX support not available
--------------------------------------------------------------------

请帮我解决。

3 个答案:

答案 0 :(得分:4)

我使用webp图像测试了你的代码,它适用于Pillow 2.9:

$ wget https://www.gstatic.com/webp/gallery3/2_webp_a.webp
>>> from PIL import Image
>>> im = Image.open("2_webp_a.webp").convert("RGB")
>>> im.save("test.jpg","jpeg")

Pillow 3.0问题#1474与您的错误有关。

让我们尝试将Pillow从3.0降级到2.9,然后重试。

答案 1 :(得分:4)

此问题现已解决。我已安装最新的libwebp库i,e libwebp-0.4.3并重新安装枕头。

Here是github问题线程,如果有人遇到同样的问题。

答案 2 :(得分:0)

pip install webptools

安装 webptools 然后:

from webptools import dwebp
print(dwebp("python_logo.webp","python_logo.jpg","-o"))

该库的工作速度有点慢,但是很容易完成您的工作。