Write custom tags into EXIF data
Question about an existing feature
What are you trying to achieve?
Is there any capability to write custom tags? For example, stable diffusion software ComfyUI writes a "prompt" tag into generated images. I was able to extract the data with exifreader and write it back into the converted jpg by specifying:
...
.withExifMerge({
IFD0: {
Software: "comfyui",
ImageDescription: <previously extracted data>,
},
})
...
This isn't ideal because ComfyUI expects the original tags when extracting a prompt from an image. So I'm wondering if there's a way to preserve the original tags, or rewrite them back into the output?
When you searched for similar issues, what did you find that might be related?
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question
The "prompt" and "workflow" tags don't keep when converting from png to jpg, even when including keepExif() or keepMetadata(). For example, using the attached image at the bottom of this post:
const buffer = await fs.readFile("ComfyUI_temp_ejdxc_00001_.png");
const output = await sharp(buffer)
.toFormat("jpg")
.keepExif()
.keepIccProfile()
.keepMetadata()
.toBuffer();
await fs.writeFile("test.jpg", output);
The original tags are missing from the output jpg.
Please provide sample image(s) that help explain this question
You can view an example of the tags I'm referring to by running the following image through e.g this extractor util.
Here is the original png (with tags):
Here is the sharp output jpg (missing tags):
These are tEXt chunks rather than EXIF, please see the existing future possible enhancement https://github.com/lovell/sharp/issues/3549