Skip to content
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

How are maxWidth and maxHeight supposed to work? #150

Open
derwaldgeist opened this issue Aug 28, 2024 · 4 comments
Open

How are maxWidth and maxHeight supposed to work? #150

derwaldgeist opened this issue Aug 28, 2024 · 4 comments

Comments

@derwaldgeist
Copy link

derwaldgeist commented Aug 28, 2024

If I am calling loadImage with maxWidth = 1024, maxHeigth = 1024, I would expect that the neither the width nor the height exceed 1024. Instead, the library seems to set the shorter length to 1024, so the other can exceed its max value. Also, the library stretches the image even if it is smaller.

As an example, I have an input image that is 3560x942. The resulting image is 3869x1024, which is even bigger than the original, and the width is over 3x larger than the maxWidth.

This also happens if I set the maxHeight to 1024 only, i.e. without a maxWidth.

I would expect that maxWidth and maxHeight are maximum values, not minimum values?

@tyrex1975
Copy link

No issues with that here. I call loadImage with maxWidth=100 and maxHeight=100 and always get a thumbnail that's never larger than 100 pixels in any direction, and always proportioned in the same ratios of the original image.

Can you post your code?

@derwaldgeist
Copy link
Author

Thanks for your response. I learned in the meantime that this only happens if you set cover to true. Yet I am still wondering why this flag overrides the maxWidth / maxHeight settings?

@tyrex1975
Copy link

tyrex1975 commented Oct 14, 2024

Yes, your 3869x1024 resulting image is correct according to the code in:
https://github.com/blueimp/JavaScript-Load-Image/blob/master/js/load-image-scale.js
(search for cover and follow the scaleUp and scaledown calcuations)

Not sure what the intention was by the author. As a workaround I'd probably just avoid the cover: true parameter and let load-image return a ratio-correct image, and then stretch it in the displayed version.

@derwaldgeist
Copy link
Author

Yes, that's what I am doing right now.

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