Option to replace EXIF metadata
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.
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.
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
Please subscribe to #3824 for updates on the provision of a new withExif() function to replace all EXIF metadata.