Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEFAULT_QUALITY causes problems for webp. #62

Open
btimby opened this issue Feb 3, 2025 · 0 comments
Open

DEFAULT_QUALITY causes problems for webp. #62

btimby opened this issue Feb 3, 2025 · 0 comments

Comments

@btimby
Copy link

btimby commented Feb 3, 2025

If you leave the default quality set to -1

When saving a webp image, you will receive the following exception ValueError: invalid configuration. This error originates from the webp handling in Pillow here:

https://github.com/python-pillow/Pillow/blob/main/src/_webp.c#L673C10-L673C28

Which in turn is calling libwebp's WebPValidateConfig() function, which is here:

https://github.com/webmproject/libwebp/blob/6a22b6709ce9e8fea5a487b37417f695df89b286/src/enc/config_enc.c#L99

It expects a value between 0 and 100. Therefore quality=-1 is an invalid value for webp images.

I am working around this by defining a default quality of 75, however, I would expect the default to be usable "out of the box". If you have some guidance on how you would like this fixed I will open a PR. I have a couple ideas:

  • Add a special case for webp format that frames the quality value between 0-100.
  • Catch this exception and if working with a webp file raise a more useful exception.
  • Disable support for webp.
  • Use the quality value from the source image (if this is available) in the default case.
  • Omit the quality parameter unless the user defined it.
  • Change the default to 75 or another valid value (see below).

Pillow docs for Image.save() say:

"The available options are described in the image format documentation for each writer."

On the file formats page, only jpeg, tiff and webp seem to accept quality. Jpeg accepts 0-95 (75 default), tiff is 0-100 (75 default) and webp accepts 0-100 (80 default). This is how I arrived at my default of 75.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant