lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.27k stars 1.3k forks source link

sharp resize image lost content #4255

Open yunmc opened 1 week ago

yunmc commented 1 week ago

Possible bug

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

System: OS: Linux 4.19 Debian GNU/Linux 9 (stretch) 9 (stretch) CPU: (4) x64 AMD EPYC 7T83 64-Core Processor Memory: 2.57 GB / 15.11 GB Container: Yes Shell: 4.4.12 - /bin/bash Binaries: Node: 12.22.12 - /usr/local/bin/node Yarn: 1.22.18 - /usr/local/bin/yarn npm: 6.14.16 - /usr/local/bin/npm npmPackages: sharp: ^0.30.7 => 0.30.7

What is the expected behaviour?

resize the picture while ensuring that the content of the picture is not lost.

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

const image = sharp(buff);
const {
  width,
  height,
} = await image.metadata();
const limit = 2173;
if (Math.min(width, height) > limit) {
  image.resize(width < height ? { width: limit } : { height: limit });
  buff = await image.jpeg({ quality: 100 }).toBuffer();
}

Please provide sample image(s) that help explain this problem

before resize: https://sigma-temp.oss-cn-shanghai.aliyuncs.com/temp_image/20241106-102659.jpg

after resize: https://sigma-temp.oss-cn-shanghai.aliyuncs.com/temp_image/20241106-102719.jpg

lovell commented 1 week ago

Node: 12.22.12 - /usr/local/bin/node sharp: ^0.30.7 => 0.30.7

Please ensure you're using the latest version of sharp with an active version of Node.js.

If you're still having problems, please provide complete, standalone, minimal code and sample image that allows someone else to reproduce.