-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Error: shrinkv: image has shrunk to nothing #1003
Comments
Hello, this is an interesting scenario that has, ahem, cropped up briefly before in #767. To support this we'd have to start ignoring the aspect ratio when either the x or y axis would reduce to <0.5px. Feedback from other sharp users would be very much welcome here. |
From a personal perspective, I've really enjoyed that sharp has really good default behavior in almost all cases I throw at it (thanks a ton!). This one caught me a little off guard. The error doesn't give any stacktrace, and while the message was clear enough for me to eventually track down the error, I'd just love for it to give me a valid image regardless of whether the aspect ratio would be off. For dynamic scripts, I feel having to calculate the expected output size would be a big hurdle. When implementing the different sizing methods, you would basically have to reimplement the calculations done internally in sharp (and keep them up to date with any changes), then check if any dimensions were less than 0.5px, and if so switch to a resizing mode that would ignore aspect ratio. In other situations, perhaps you would want an error to be emitted, but if so, I would expect a clearer and more decorated error message. So I'd either go with an option that set which behaviour to use (ignore aspect ratio on < 0.5px, or throw on invalid dimensions). |
I would vote for a lower limit set at 1px for either dimension to accommodate for older screens. And beyond that limit to ignore the aspect ratio for the final resize. |
It would be nice to have the ability to provide a flag when resizing an image, like |
Commit 7c631c0 adds a couple of tests that highlight this problem along with the fix to ensure the length of the shortest edge never rounds below one pixel. |
v0.21.2 now available with this feature, thank you for the original suggestion. |
Hi,
If you use an image that is 2000x4 and resize to 100px in width using
img.max().resize(100)
, you will get this error:Error: shrinkv: image has shrunk to nothing
.I'm not sure if you consider this to be something that should be handled by the user before passing the size on to sharp, but I would have loved if it simply capped it at 1px in height to avoid the error.
Thoughts?
The text was updated successfully, but these errors were encountered: