exifr
exifr copied to clipboard
Adding/copying EXIF to a file?
I'm currently resizing JPEGs in the frontend with Pica before uploading to the server. The problem is that the resized images lose any EXIF metadata. Unfortunately I couldn't figure out a way to solve this with Pica.
Now I'm considering introducing another library, but it's not clear from the documentation if this library merely allows to read EXIF? Or is it possible to copy the header and add to another image file? Is there a demo on that or some example?
Thanks for the library!
Hello. This is an interesting issue that can get very tricky. It's not set implemented (nor is creating or editing the tags). I was thinking about it already. I think I will be implementing this soon, when I get back from vacation.
That is copying exif buffer from one file to another. It will only be doable for jpegs (as other formats have more complex data structures) and I will have to modify some tags related to the width and height of the file to match the target.
@MikeKovarik thanks for the prompt response!
A simpler solution (that can be helpful on its own) would be if when reading the metadata, the positions of the metadata in the file could be extracted.
My scenario is that I resize 5MB images to 10KB images in the frontend before uploading. The problem is that all metadata is lost during the resize. So initially I thought to add the header to the resized image before sending. I later figured that I can merely just send the first 128-256KB of the original file separately and simply do the hard work in the backend (glue back the header with exiftool
or similar or just extract the metadata there if I need to).
The main issue with the above, is that many times I end up still sending an unnecessarily huge chunk of the original file. E.g. sending 256KB for a 10KB file, when the header might be in the first 1024 bytes. So simply just knowing the positions for the metadata would mean that I don't need to send anymore that huge chunk but just from the beginning to the rightmost where the metadata was found.
This seems like a separate feature, but seems simpler and quite generic so I would think it can be used in many different scenarios as well (possibly including editing tags, etc.).
Hello, I can't be that much helpful from my phone but from what I understand you could something that's already built in. Before parsing exifr first looks for all metadata segments and stores them in array that's accessible if you use the Exifr class instead of the high level functioms like exifr.parse.
It is undocumented (because the docs are already long :D ) but it isn't going to get away. It's used in few of my debug helper scripts below.
https://github.com/MikeKovarik/exifr/blob/master/debug/seglog.js https://github.com/MikeKovarik/exifr/blob/master/debug/segments.mjs https://github.com/MikeKovarik/exifr/blob/master/debug/segorder.js https://github.com/MikeKovarik/exifr/blob/master/debug/segstat.mjs
From here it shouldn't be that big of a problem to implement this in exifr (and the metadata copying would work directly in browsers so you wouldn't have to go through the backend & imagemagik hoops). I'll be available more in a week or so after my vacations. For now. Good luck:)