14

I have written small program to convert webp to jpg in python

import imghdr
from PIL import Image

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

when executing it gives me following error

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'

I have installed pillow with webp capability. Here is my pillow installation output

--------------------------------------------------------------------
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
--------------------------------------------------------------------

Please help me how to proceed.

Sandeep Kumar Singh
  • 275
  • 1
  • 4
  • 13
  • I've never used WebP, but your code _should_ work. Can you verify that "unnamed.webp" is actually a valid WebP file, eg using ImageMagick's `identify` or `convert` commands? – PM 2Ring Oct 23 '15 at 07:00
  • 1
    Here is output of file command in linux `$ unnamed.webp: RIFF (little-endian) data` output of imagemagick `$ 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.` – Sandeep Kumar Singh Oct 23 '15 at 07:12
  • Sorry, I should've mentioned that older versions of ImageMagick _may_ not have WebP surpport. All I can suggest is to do a hexdump to check that the first 12 bytes of the file match the header shown in the [WebP Wikipedia article](https://en.wikipedia.org/wiki/WebP#Technology). And maybe try to find some more WebP files to test. – PM 2Ring Oct 23 '15 at 07:28
  • File is correct I have verified from wikipedia – Sandeep Kumar Singh Oct 23 '15 at 07:35

4 Answers4

13

I tested your code with a webp image and it works with 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")

There's Pillow 3.0 issue #1474 related with your error.

Let's you try to downgrade Pillow from 3.0 to 2.9 and try again.

Paolo Melchiorre
  • 5,716
  • 1
  • 33
  • 52
7

This issue has been resolve now. I have install latest libwebp library i,e libwebp-0.4.3 and reinstall pillow.

Here is github issue thread if some one face same issue.

Sandeep Kumar Singh
  • 275
  • 1
  • 4
  • 13
2

Install webptools by pip install webptools and then:

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

This library works bit slow but is easy to do your work.

Majid Hajibaba
  • 3,105
  • 6
  • 23
  • 55
Prajot Kuvalekar
  • 5,128
  • 3
  • 21
  • 32
0

Load image with webp and proceed

from PIL import Image
import webp

im = webp.load_image('test.webp').convert('RGB')
im.save('test.jpg', 'jepg')