You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot convert high resolution jpg file to webp #5461
I read in a high resolution jpg image, and convert it to webp format.
What did you expect to happen?
I expected to get a image file with webp format
What actually happened?
I have a image with resolution 4500*6500 and when I direct save this image as webp format, Pillow gives me the error:
Traceback (most recent call last):
File "/Users/martin/software/miniconda3/envs/py36/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
File "/Users/martin/software/miniconda3/envs/py36/lib/python3.6/site-packages/PIL/Image.py", line 2172, in save
save_handler(self, fp, filename)
File "/Users/martin/software/miniconda3/envs/py36/lib/python3.6/site-packages/PIL/WebPImagePlugin.py", line 337, in _save
xmp,
ValueError: encoding error
I also tried to crop this image to 4500*4500 and save it to webp format. And I get the same "ValueError: encoding error" error.
I tried to crop this image to 4000*4000 and save it to webp format. This time, there's no error and I get the result webp file.
What are your OS, Python and Pillow versions?
OS: Mac OS X El Capitan (10.11.6)
Python: 3.6.4
Pillow: 8.2.0
it works. In the next version of Pillow, #5450 will mean that the new default will be 4 - so you will no longer have to add on method to fix this issue.
Looking at the error that is thrown, it is error code 6 from webp, PARTITION0_OVERFLOW - "partition is bigger than 512k". So it makes sense that a larger image is triggering this.
This might just be how webp chooses to behave? I'm not personally in favour of automatically restricting the quality of the image to fit that. The only amends we could do might be to show a clearer error message.
@radarhere This make sense. I also tried to save as webp in my windows 10 computer with mode=4 and it also gave me the xmp error. But if I reduce the quality from 90 to 85, this process will work fine.
Hi, if I get error 6 when saving webp (tried through method from 0 to 6), what can I do to avoid it?
It seems that this issue only improve error reporting, rather than giving a way to fix it
well, it's hard to get the exactly the original image, since I'm not using Pillow directly, but getting the error when generating a big xyz plot in A1111 stable diffusion webui
according to cwebp's document about -partition_limit, I would suspect that webp not only has a hard coded size limit of 16383 pixels, but also has a soft limit of "Partition0 Size" when:
total pixels go near 16383*16383,
and/or has complex content
and/or set to high quality setting
at the same time
I add a detection to change the file format to jpeg or png when total pixels > 16383**2//2 to workaround that.
maybe Pillow can expose other cwebp parameters so that it can be further diagnosing?
Activity
radarhere commentedon May 2, 2021
Could we get a copy of "xxxxx.jpg"?
ma-tongji commentedon May 3, 2021
I upload a copy at: http://47.74.156.104/89218229_p0.jpg.zip
radarhere commentedon May 3, 2021
Strangely enough, I find that if I specify
methodto a value greater than 1 in the last line of your code,it works. In the next version of Pillow, #5450 will mean that the new default will be 4 - so you will no longer have to add on
methodto fix this issue.ma-tongji commentedon May 3, 2021
@radarhere Thanks, I will try the method argument first for now.
radarhere commentedon May 3, 2021
Looking at the error that is thrown, it is error code 6 from webp, PARTITION0_OVERFLOW - "partition is bigger than 512k". So it makes sense that a larger image is triggering this.
This might just be how webp chooses to behave? I'm not personally in favour of automatically restricting the quality of the image to fit that. The only amends we could do might be to show a clearer error message.
radarhere commentedon May 4, 2021
@ma-tongji to check, are you satisfied with this as a solution for your problem?
radarhere commentedon May 6, 2021
I've created PR #5471 to show the error code - 6 in this case - to the user, so that this would be clearer in future Pillow versions.
ma-tongji commentedon May 9, 2021
@radarhere This make sense. I also tried to save as webp in my windows 10 computer with mode=4 and it also gave me the xmp error. But if I reduce the quality from 90 to 85, this process will work fine.
SLAPaper commentedon Aug 23, 2023
Hi, if I get error 6 when saving webp (tried through method from 0 to 6), what can I do to avoid it?
It seems that this issue only improve error reporting, rather than giving a way to fix it
radarhere commentedon Aug 23, 2023
I suspect you could reduce the quality when saving. Could you attach a copy of the image?
SLAPaper commentedon Aug 23, 2023
well, it's hard to get the exactly the original image, since I'm not using Pillow directly, but getting the error when generating a big xyz plot in A1111 stable diffusion webui
according to cwebp's document about -partition_limit, I would suspect that webp not only has a hard coded size limit of 16383 pixels, but also has a soft limit of "Partition0 Size" when:
at the same time
I add a detection to change the file format to jpeg or png when total pixels > 16383**2//2 to workaround that.
maybe Pillow can expose other cwebp parameters so that it can be further diagnosing?
radarhere commentedon Aug 23, 2023
If you're not using Pillow directly, how would you plan to address this with whatever advice we might provide?
SLAPaper commentedon Aug 23, 2023
Just found this issue that have related errorcode reporting and wonder whether there is something worth discuss.
Sorry for disturbing