webp save methods do not support 'target_size' parameter #3822
john-parton
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
Hello @john-parton, You're right, libvips doesn't expose all the webp save options. I've never needed the save-as-size feature so I wasn't sure how useful it was. We should probably add it. Your 2. option isn't that bad -- you can do a binary search and find a good Q factor in only a few iterations. I imagine libwebp is doing something like that internally. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The webp API supports saving with a "target_size" parameter to limit the maximum size of the resulting file.
https://developers.google.com/speed/webp/docs/api
As far as I can tell, this isn't exposed in libvips (and consequently pyvips, the binding I am using.)
This is a useful feature for my use case. I preprocess images before they are sent to CloudFlare Images. They have specific limits for resolution, but also an overall limit for file size. In my case, I set images to be at most 6,000 x 6,000 pixels and am saving with Q=90. For the vast majority of images, that's fine, because the resulting image is usually significantly less than 10MB, but for some noisy images with difficult to compress features, it just barely goes over the 10MB boundary.
If I could just pass this in, I wouldn't have to worry about, but now I'm faced with having to either:
I wouldn't really consider either of these to be a good solution.
Beta Was this translation helpful? Give feedback.
All reactions