【发布时间】:2016-01-22 15:08:54
【问题描述】:
我写了一个小程序,在python中将webp转换为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
--------------------------------------------------------------------
请帮助我如何进行。
【问题讨论】:
-
我从未使用过 WebP,但您的代码应该可以工作。您能否验证“unnamed.webp”实际上是一个有效的 WebP 文件,例如使用 ImageMagick 的
identify或convert命令? -
这是linux中文件命令的输出
$ unnamed.webp: RIFF (little-endian) dataimagemagick的输出$ convert: no decode delegate for this image format 'unnamed.webp' @ error/constitute.c/ReadImage/532. convert: missing an image filename '/dev/null' @ error/convert.c/ConvertImageCommand/3011. -
抱歉,我应该提到旧版本的 ImageMagick 可能不支持 WebP。我只能建议做一个 hexdump 来检查文件的前 12 个字节是否与WebP Wikipedia article 中显示的标头匹配。并且也许尝试找到更多的 WebP 文件进行测试。
-
文件是正确的我已经从维基百科验证了