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?
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?
Trying to resize a 96dpi image using withExif(object) feature, the default option density: 72 is not respected.
The resulting image has 96dpi in metadata.
And there is no way to strip Xmp, Iptc and ICC profile, when using withMetadata({density: 72}).
What is the expected behaviour?
The default option density: 72 is respected.
A way to strip Xmp, Iptc and ICC profile, cloud be desiderable.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
const sharp = require('sharp');
const exif = {IFD0: {UserComment: 'A comment'}};
sharp(image.jpg, {
density: 72 // default
})
.resize({width: 600})
.jpeg({trellisQuantisation: true})
.withExif(exif)
.toFile(out.jpg) // 96dpi from metadata (strip all, Exif)
.then(info => console.log(info))
.catch(err => console.error(err));
/* attempt to force 72dpi metadata */
sharp(image.jpg, {
density: 72 // default
})
.resize({width: 600})
.jpeg({trellisQuantisation: true})
.withMetadata({
density: 72 // forces 72dpi metadata
//, exif // same as below
})
.withExif(exif)
.toFile(out.jpg) // 72dpi from metadata (Exif, no strip Xmp Iptc ICC)
.then(info => console.log(info))
.catch(err => console.error(err));
Activity
ctlcltd commentedon Feb 8, 2026
I solved with this workaround, to obtain strip all and 72dpi from metadata.
Thank you so much, very happy to use your library.
lovell commentedon Feb 8, 2026
Please see #3017 (comment)
ctlcltd commentedon Feb 8, 2026
I already searched the closed issues and I saw that.
I think is another issue, related to the default option correctness. The default sharp.Options option
densityis ignored usingwithExif, the resulting jpeg image will have 96dpi in metadata.The resulting image is ok and resized, but it has 96dpi in metadata, maybe XReso and YReso come from the original metadata, maybe from XMP metadata. When using
withMetadata({ density: 72 })it correctly applies 72dpi in the metadata, but strip all will be turned off.With the default options, without
withExifis 96 to 72, usingwithExifis 96 to 72. If you open the resulting jpeg file with a software, it opens it to 96dpi resolution.I don't know if this is an important issue.
ctlcltd commentedon Feb 11, 2026
@lovell an update. I'm trying sharp, vips cli, wasm-vips to generate thumbnails, the keep-exif behavior is identical.
My origin file has xres,yres = 96dpi (~3.78 px/mm). I prefer images without this data 96dpi. Softwares, including viewers, are applying this data.
So xres/yres should be set to 72 (~2.83 px/mm) before saving. This can be achieved with sharp using
withMetadata({ density: 72 }), but there is no strip at all.In a comparison, this is vips cli:
This is sharp, with a custom exif:
I'm concluding, I don't know what is the best method with sharp to: strip all metadata, custom exif, Xres/Yres (density) to 72dpi.
lovell commentedon Mar 4, 2026
The
densityconstructor property only applies to vector images and I've clarified this via commit ff4626d.The use of
withMetadataensures the presence of EXIF metadata, which is necessary for a JPEG image to contain density information. Without this, JPEG images do not contain any density information. The function also ensures/adds an ICC profile as documentedIf you only want to set EXIF metadata then please see withExif.
lovell commentedon Mar 7, 2026
I think this relates to libvips always replacing
XResolutionandYResolutionvalues with its internalxresandyres(which use pixels/mm):https://github.com/libvips/libvips/blob/460579a2a93bbd4c482fb22f01af9624b2ca72d5/libvips/foreign/exif.c#L1459-L1468
When you call
withMetadata({ density })these values are set, butwithExifdoes not. Perhaps a newwithDensity(density)is required to offer more fine-grained control over the output density?Add withDensity to set density in EXIF metadata #4496
[-]Image density 96dpi from metadata and default density is 72dpi, using withExif[/-][+]Add withDensity for fine-grained control over EXIF resultion data[/+]lovell commentedon Jun 10, 2026
v0.35.0 now available providing support for
withDensity:https://sharp.pixelplumbing.com/api-output/#withdensity
chore(deps): update dependency sharp to ^0.35.5 (#9)