Skip to content

Possible logic error in scaling ('encodeMaxPixelSize' option) #64

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

Closed
AlexDjr opened this issue Jun 19, 2022 · 3 comments
Closed

Possible logic error in scaling ('encodeMaxPixelSize' option) #64

AlexDjr opened this issue Jun 19, 2022 · 3 comments

Comments

@AlexDjr
Copy link

AlexDjr commented Jun 19, 2022

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

@dreampiggy
Copy link
Contributor

dreampiggy commented Jun 20, 2022

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
Copy link
Contributor

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
Copy link
Contributor

Fixed in v0.8.5 and v0.9.0

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

2 participants