sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Option to replace EXIF metadata

Open stackcoder opened this issue 4 years ago • 1 comments

What are you trying to achieve? Discard all existing metadata of an image and only write entries specified within withMetadata to the file. The current behavior merges existing entries with the new ones.

Have you searched for similar questions? Sure at least: #650, #2724, #2812, #2638, #2507

The strip tag of libvips is !baton->withMetadata controlled by !baton->withMetadata. So might be difficult to combine strip and updating metadata together within libvips. Is there any other option instead encoding the image twice?

// My current workaround:
sharp.prototype.discardMetadata = async function () {
  const {data, info} = await this
    .raw()
    .toBuffer({resolveWithObject: true});
  return sharp(data, {raw: info});
};

Are you able to provide a minimal, standalone code sample that demonstrates this question? Already exists, there you go: https://sharp.pixelplumbing.com/api-output#withmetadata

Are you able to provide a sample image that helps explain the question? Not required.

stackcoder avatar Sep 30 '21 16:09 stackcoder

Perhaps the API could look something like the following:

// PROPOSED API - NOT YET AVAILABLE
.withMetadata({
  exif: { key: "value" },
  exifReplace: true
})

Happy to accept a PR, if you're able.

lovell avatar Oct 20 '21 19:10 lovell

This is being covered as part of the work integrating the new "keep" metadata feature of libvips - see https://github.com/lovell/sharp/issues/3824#issuecomment-1809148065

lovell avatar Nov 14 '23 22:11 lovell

Please subscribe to #3824 for updates on the provision of a new withExif() function to replace all EXIF metadata.

lovell avatar Nov 15 '23 15:11 lovell