Closed mpirescarvalho closed 3 years ago
It should be possible, but the .exif property is the raw, already-encoded EXIF data as it's found in the WEBP itself. It was outside the scope at the time to actually parse the EXIF chunk, and it's mostly kept (along with the XMP and ICC chunks) so that they don't get stripped out when re-saving WEBPs that have them defined.
I have a .webp
and a .exif
file
using webpmux binary I could do:
webpmux -set exif image_metadata.exif in.webp -o exif_container.webp
would that be possible with this library?
At the moment, no. There's currently no way to save non-animated WEBPs.
I'll see about adding the ability to save non-animated WEBPs later today. I should have time. This library was originally intended mostly for reading metadata (as I couldn't find anything out there, not even the webpmux binary, that would give me access to the level of detail I needed at the time about stored animations). However, I do see the benefit to having the ability to set EXIF/ICC/XMP like this and feel a little silly for not already implementing it properly.
And just to mention:
I think this sould be:
...createBasicChunk('EXIF', this.data.exif.raw)
instead of:
...createBasicChunk('EXIF', this.data.extended.exif.raw)
Just pushed an update containing a .save and a static Image.save. Also fixed the EXIF/XMP/ICC chunk saving, as you're right, it should've been this.data.exif.raw
. Feel free to re-open this if the save function doesn't work as expected.
I'm sorry, but there's still something wrong, and I couldn't figure out if it is on my end.
Take a look at these two images (github doesn't support webp, so I'm sending prints):
I used webpmux binary to set the exif data to this webp file, and it opens as expected:
This other one I used your library to set the exif data, but it broke the image:
Now, looking at the images as text, I can see that the webpmux binary puts the exif data at the end:
While your library puts it at the top:
Maybe this is causing the images to be broken?
This is how I'm setting the data:
let img = new NodeWebP.Image();
await img.load(resultPath);
img.exif = exif
await img.save(resultPath);
It's the same data for both images
Sorry about that. Never write code when half asleep and forget to test afterwards. It should hopefully work now.
It didn't work 🙁
Is there something I can do to help?
I'm not really sure. From my (admittedly limited) testing using GIMP to write the metadata, it works as expected. Both extracting the EXIF chunk to file via the webpmux binary and this library, as well as setting the EXIF chunk produce identical, working images. Does it work when using the webpmux binary set the EXIF data? If it does, could you upload the images/EXIF file somewhere and I can take a look?
Does it work when using the webpmux binary set the EXIF data?
Yes, it works.
I've upload the files to this repo
Files:
exif-data.exif: the actual exif data
raw-image.webp: the original source image
webpmux-bin-image.webp: the image that was created using webpmux binary
node-webpmux-image.webp: the image that was created using node-webpmux
Note that the webpmux bin generated one opens normally, while the node-webpmux generated do not
Thanks. Should be definitely fixed now. Tested by loading webpmux-bin-image.webp and saving it. Output is identical, and displays fine in Chrome. Turns out the order the chunks are saved matters more than I thought. I don't recall the documentation mentioning that the ALPH chunk must come before the VP8 chunk or it's not a valid image.
It worked, many thanks!
It's possible to set exif data for NOT ANIMATED webp files? I see the exif property but I'm not sure how could I save it back to a file