You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears as though there are rounding errors that occur in certain scenarios when auto scaling the height of images during resizing. In my specific case, calling resize(300, null) on a 165x220 JPG results in an image that's 300x399 rather than 300x400.
The text was updated successfully, but these errors were encountered:
Hi Richard, thanks for reporting this problem. It looks like the cause is a (lack of) floating point precision.
The closest double-precision floating point value to the integer value of 400 is 399.999999999999943156581139191985130310058593750, which is converted to 399 by floor.
For the auto-scaling width and height calculations, I think we may have to instead use round (I need to remember why floor was used here in the first place) or add a very small number e.g. 0.000000001 before floor. Leave it with me.
Commit b8885c1 on the knife branch switches from the use of floor to round, which improves the "safety" of converting from float to integer, but also makes the resultant dimensions more closely match users' expectations.
This will be part of the forthcoming v0.11.0 release, but you can test now using:
npm install lovell/sharp#knife
(I'd prefer to avoid a patch-release for this as it introduces a slight change to existing behaviour.)
Thanks again for reporting this - I'm amazed it has taken this long to come up.
It appears as though there are rounding errors that occur in certain scenarios when auto scaling the height of images during resizing. In my specific case, calling
resize(300, null)
on a 165x220 JPG results in an image that's 300x399 rather than 300x400.The text was updated successfully, but these errors were encountered: