SDWebImageWebPCoder
SDWebImageWebPCoder copied to clipboard
Possible logic error in scaling ('encodeMaxPixelSize' option)
Hi!
I'm using SDWebImageWebPCoder to convert my images to WEBP and have stumbled upon what looks like a logic error in scaling with encodeMaxPixelSize option.
The case looks like this:
-
I have an image with size of 1253x403 and I'm trying to scale it to fit in 512x512 size

-
and it does nothing, the image's size remains 1253x403
-
I checked the code and found line 871 in SDImageWebPCoder:

What it says is that width and height of an image should be both larger than respective size values of encodeMaxPixelSize option. So in my case I don't meet this condition because my height (403) is smaller than 512.
Shouldn't it be OR instead of AND in this condition?

For my case such fix works correctly: 1253x403 image has been scaled to 512x165 size
Please guide me if I'm missing something about this logic
This logic seems wrong...
In general, this should works as aspect fit scale down, not aspect fill. So you're correct.
I'll fix today with new patch version :)
Need to fix SDWebImage Core logic as well...
https://github.com/SDWebImage/SDWebImage/blob/5.12.6/SDWebImage/Core/SDImageIOCoder.m#L255
Actually I can adjust this condition into a function to make its behavior matches across the libraries.
Fixed in v0.8.5 and v0.9.0