SDWebImageWebPCoder icon indicating copy to clipboard operation
SDWebImageWebPCoder copied to clipboard

Possible logic error in scaling ('encodeMaxPixelSize' option)

Open AlexDjr opened this issue 3 years ago • 2 comments
trafficstars

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 image

  • and it does nothing, the image's size remains 1253x403

  • I checked the code and found line 871 in SDImageWebPCoder: image

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? image

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

AlexDjr avatar Jun 19 '22 09:06 AlexDjr

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 :)

dreampiggy avatar Jun 20 '22 03:06 dreampiggy

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.

dreampiggy avatar Jun 20 '22 03:06 dreampiggy

Fixed in v0.8.5 and v0.9.0

dreampiggy avatar Sep 09 '22 10:09 dreampiggy