Image metadata won't update
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?
- [x] 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?
const img = sharp("./input.png")
await img.metadata() // This would return width: 500 and height: 500, for example
img.resize(200, 200)
await img.metadata() // Metadata will not change and will return width: 500 and height: 500 as well
What is the expected behaviour?
Update the metadata and return the new values
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
up
Please provide sample image(s) that help explain this problem
Hello, did you see https://sharp.pixelplumbing.com/api-input#metadata ?
This is read from the header of the input image. It does not take into consideration any operations to be applied to the output image, such as resize or rotate.
Hmm so I should modify the image/buffer once i get the metadata and return a buffer?
const data = await img.resize(200, 200).toBuffer()
const info = await sharp(data).metadata()
or
const { data, info } = await img.resize(200, 200).toBuffer({ resolveWithObject: true })
Great, I will try this solution and once I check it, I will close this issue.
@simxnet Were you able to make any progress with this?
I hope this information helped. Please feel free to re-open with more details if further assistance is required.