Pillow: 8192px * 8192px --> cannot write file as WEBP (encoder returned None)

Created on 11 Dec 2014  路  5Comments  路  Source: python-pillow/Pillow

I was trying to save a big sprite map as webp for testing purposes.
Then I ran into

File "*/pip-srcs/Pillow/PIL/Image.py" in save
  1682.             save_handler(self, fp, filename)
File "*/pip-srcs/Pillow/PIL/WebPImagePlugin.py" in _save
  71.         raise IOError("cannot write file as WEBP (encoder returned None)")

I already tried to let the code run with the current 'master' state.
And again with libwebp-0.4.2. It did not help.

It seems to be an issue on the resulting file size.
Since if I use a 'quality' parameter lower than 90 for a specific image, it suddenly works.
The 'quality' seems to depend on the information-richness of the image, too.
The more different colors are used in the image, the higher is the probability that the saving fails for on level of 'quality'.

Bug

Most helpful comment

I have the same issue and it's keeping me from using webp on my production system.
I would guess it's about the size of the image.
Code to use:
```from PIL import Image
pilImage = Image.new('RGB', (16495, 200), color=(900,100,100))

works:

pilImage.save(r'D:\exc.jpg', quality=40)

crashes:

pilImage.save(r'D:\exc.webp', quality=40)
```

Edit:
I have downloaded the command line tool from googles webp repository.
cwebp -q 40 exc.jpg -o exc_cmd.webp
It says when trying to encode the .jpg to .webp:
Error code: 5 (BAD_DIMENSION: Bad picture dimension. Maximum width and height allowed is 16383 pixels.)
If one searches a bit it is in their FAQ (but not on other more prominent places)

WebP is bitstream-compatible with VP8 and uses 14 bits for width and height. The maximum pixel dimensions of a WebP image is 16383 x 16383.

So at least with these dimensions you cannot save in webp format.
So we need to wait for HEIF-AV1: AVIF...

All 5 comments

Can you say any more about this issue? Is it a Pillow bug?

Would you be able to provide the problem image, so that we can try and replicate the issue more easily?

I encountered this error on AWS Lambda. It co-occurs with the lambda instance running out of memory and failing, so might be related to that. I wish I could provide the problematic image, but Lambda logging sucks... I'll do some more research.

I am unable to replicate this. The following code works for me with macOS 10.14, Python 3.7.0, Pillow 5.2.0 and libwebp 1.0.0

from PIL import Image
im = Image.open("Tests/images/hopper.jpg")
im = im.resize((8192, 8192))
im.save("test.webp")

Closing, as I am unable to replicate, and there is no further information.

I have the same issue and it's keeping me from using webp on my production system.
I would guess it's about the size of the image.
Code to use:
```from PIL import Image
pilImage = Image.new('RGB', (16495, 200), color=(900,100,100))

works:

pilImage.save(r'D:\exc.jpg', quality=40)

crashes:

pilImage.save(r'D:\exc.webp', quality=40)
```

Edit:
I have downloaded the command line tool from googles webp repository.
cwebp -q 40 exc.jpg -o exc_cmd.webp
It says when trying to encode the .jpg to .webp:
Error code: 5 (BAD_DIMENSION: Bad picture dimension. Maximum width and height allowed is 16383 pixels.)
If one searches a bit it is in their FAQ (but not on other more prominent places)

WebP is bitstream-compatible with VP8 and uses 14 bits for width and height. The maximum pixel dimensions of a WebP image is 16383 x 16383.

So at least with these dimensions you cannot save in webp format.
So we need to wait for HEIF-AV1: AVIF...

Was this page helpful?
0 / 5 - 0 ratings