I have a Node.js server whose job it is to download JPEG images, write certain data to a couple of IPTC fields (e.g. Iptc.Application2.Caption
) and pass the image on to another service.
Ideally, I'd like to write the IPTC data to the in-memory buffer (without writing the image to the local file system). Failing that, I can live with a solution where I download, store the file to the FS, then apply the IPTC data.
I've got this working with https://github.com/dberesford/exiv2node, but it doesn't work on Node.js v10. And it depends on exiv2 C++ library which makes it messy to run containerized.
So my question is: Is there a decent Node.js module which enables IPTC data write, and does not depend on some monster C library?
I would use exiftool-vendored, that it just a wrapper for the exiftool command line utility. It will also install the exiftool binary, if you have already installed exiftool you can use exiftool without this binary
Install exiftool:
npm install --save exiftool-vendored
The tags you add are put in the specifications that supports them, in this case IPTC.
For example I will add Artist and Copyright tags, and exiftool will put the correspondent IPTC tags.
const exiftool = require("exiftool-vendored").exiftool
const tags = {
artist:"David Lemon",
copyright:"2018 David Lemon"
};
exiftool.write("outernet.jpeg", tags);
exiftool.write
will return a promise that you can wait for while computing another things. More info on promises.
Using the exiftool CLI you can check that the tags are well written to the file:
$ node_modules/exiftool-vendored.exe/bin/exiftool.exe outernet.jpeg
ExifTool Version Number : 11.20
File Name : outernet.jpeg
Directory : .
File Size : 4.6 kB
[...]
Artist : David Lemon
Y Cb Cr Positioning : Centered
Copyright : 2018 David Lemon
Current IPTC Digest : 2b3df19b0c67788262a0d0dced3b6d58
Coded Character Set : UTF8
Envelope Record Version : 4
[...]