anibali / pywebp

Python bindings for WebP
MIT License
74 stars 24 forks source link

pywebp doesn't expose "target_size" parameter to limit the maximum size of the resulting file. #64

Closed john-parton closed 6 months ago

john-parton commented 6 months ago

The webp API supports saving with a "target_size" parameter to limit the maximum size of the resulting file.

int target_size;        // if non-zero, set the desired target size in bytes.
                        // Takes precedence over the 'compression' parameter.

https://developers.google.com/speed/webp/docs/api

As far as I can tell, this isn't exposed in pywebp.

This would be a useful feature for me, because I'm using CloudFlare images with has a hard 10MB cap on image size. It would be nice to just set the file size to just under 10MB and remove guesswork about appropriate Q values.

See also:

anibali commented 6 months ago

I just had a go at implementing this in https://github.com/anibali/pywebp/issues/64. Would that PR meet your needs?