在 python 中将 webp 图像文件转换为 jpg 时出错
Error while converting webp image file to jpg in python
我写了小程序把webp转成jpg python
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 图像测试了你的代码,它适用于 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,然后重试。
此问题现已解决。我已经安装了最新的 libwebp 库 i,e libwebp-0.4.3 并重新安装了 pillow。
Here 是 github 如果有人面临同样的问题,请发帖。
通过 pip install webptools
安装 webptools
然后:
from webptools import dwebp
print(dwebp("python_logo.webp","python_logo.jpg","-o"))
这个库工作起来有点慢,但很容易完成你的工作。
我写了小程序把webp转成jpg python
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 图像测试了你的代码,它适用于 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,然后重试。
此问题现已解决。我已经安装了最新的 libwebp 库 i,e libwebp-0.4.3 并重新安装了 pillow。
Here 是 github 如果有人面临同样的问题,请发帖。
通过 pip install webptools
安装 webptools
然后:
from webptools import dwebp
print(dwebp("python_logo.webp","python_logo.jpg","-o"))
这个库工作起来有点慢,但很容易完成你的工作。