Repository navigation
Description
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
- Running
npm install sharpcompletes without error. - Running
node -e "require('sharp')"completes without error.
If you cannot confirm both of these, please open an installation issue instead.
Are you using the latest version of sharp?
- I am using the latest version of
sharpas reported bynpm view sharp dist-tags.latest.
If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.
What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?
System:
OS: macOS 15.1
CPU: (11) arm64 Apple M3 Pro
Memory: 216.06 MB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.11.0 - /usr/local/bin/node
pnpm: 9.10.0 - /usr/local/bin/pnpm
bun: 1.1.12 - /opt/homebrew/bin/bun
npmPackages:
sharp: ^0.33.5 => 0.33.5
Does this problem relate to file caching?
The default behaviour of libvips is to cache input files, which can lead to EBUSY or EPERM errors on Windows.
Use sharp.cache(false) to switch this feature off.
- Adding
sharp.cache(false)does not fix this problem.
Does this problem relate to images appearing to have been rotated by 90 degrees?
Images that contain EXIF Orientation metadata are not auto-oriented. By default, EXIF metadata is removed.
-
To auto-orient pixel values use the parameter-less
rotate()operation. -
To retain EXIF Orientation use
keepExif(). -
Using
rotate()orkeepExif()does not fix this problem.
What are the steps to reproduce?
Download this png
curl -JO https://images.bookroo.com/site/landing/homepage/book-collection.pngThen run the following code:
const sharp = require('sharp');
const fs = require('fs');
async function main() {
const buffer = fs.readFileSync('./book-collection.png');
const start = performance.now();
const optimizedBuffer = await sharp(buffer).resize(1850).avif({ quality: 55 }).toBuffer();
console.log(performance.now() - start);
return optimizedBuffer
}
main().catch(console.error);What is the expected behaviour?
Should take about 800ms but it actually takes 2700ms.
You can see the difference if you change .resize(1850) to .resize(1849).
Activity
kleisauke commentedon Nov 21, 2024
Triage: this looks like the same issue as libvips/libvips#2983 as completely disabling IntraBC mode (see e.g. commit kleisauke/libheif@9aff88d) makes the timings more expected.
Before:
After:
lovell commentedon Nov 21, 2024
Thanks Kleis, I agree with your assessment, maybe we should use your libheif patch with the prebuilt binaries for now?
kleisauke commentedon Nov 21, 2024
Patching the prebuilt binaries sounds like a good plan to me.
styfle commentedon Nov 26, 2024
Is there I can get a prebuilt binary with the patch to test this and see if the patch fixes it?
Or is this a PR where I could follow along?
lovell commentedon Nov 26, 2024
@styfle Please see libvips/libvips#2983 (comment) if you'd like to follow along - there are changes to both libheif and libvips required for this.
styfle commentedon Apr 4, 2025
@lovell Looks like libvips/libvips#2983 shipped.
What are the steps to get this into sharp? Thanks!
lovell commentedon Apr 4, 2025
sharp v0.34.0 provides libvips v8.16.1 so I'll close, thanks for the original report.
fix(next/image): bump [email protected] (#77839)