Closed mowolf closed 1 month ago
Hi, did you see the fastShrinkOnLoad
option?
https://sharp.pixelplumbing.com/api-resize
Param | Type | Default | Description |
---|---|---|---|
[options.fastShrinkOnLoad] | Boolean |
true |
Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension. |
Thank you, I was blind! Disabling fastShrinkOnLoad
fixes the issue as expected.
Resize with fit: "inside" creates 1px wrong output dimensions
sharp
as reported bynpm view sharp dist-tags.latest
.Output of running
npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp
:What are the steps to reproduce?
Apply the resizing operation
{ width: 1800, height: 1200, fit: "inside" }
on an image of size 3279x6016 px.This creates an image with a width of one pixel less than expected (=changes the aspect ratio without any need to do so).
The original aspect ratio is 3279/6016=0.545.
The resulting image that sharp creates is of size
width: 653, height: 1200
with an aspect ratio of653 px/1200 px =0.544
This does only happen for certain image dimensions. We used this code on over >1M images and only a few dimensions have this problem.
What is the expected behaviour?
The created image should be 654 px wide. Resizing an image with fit: "inside" should keep the aspect ratio (as close as possible to the original).
The limiting dimension here is the width. Calculating the down-scaling factor:
f = 1200 px/6016 px = 0.1994680851
Calculating the resulting dimensions:
expectedWidth = f * 3279 px = 654.05585106383 px = 654 px
expectedHeight = f * 6016 px = 1200 px
Expected Aspect Ratio = 0.545
This is a small difference, but lead to a long bug hunt as our program computed the expected dimensions and these did not fit with the created image from sharp.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
This logs:
Please provide sample image(s) that help explain this problem
https://github.com/user-attachments/assets/7aba2e9a-f0d6-4a8c-9214-0c650216e1e8