3

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?

Yves M.
  • 29,855
  • 23
  • 108
  • 144
thomax
  • 9,213
  • 3
  • 49
  • 68

1 Answers1

7

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
[...]
David Lemon
  • 1,560
  • 10
  • 21
  • 1
    Hi @David, is there any npm which does not depend on Binary tool?. Something which can run in browser. – Sandy Dec 03 '18 at 11:51
  • 1
    No, it is dealing with archives that are stored on a server and is an input/output expensive task, it's definitely a server job. Usually you can run this kind of jobs as cron jobs. – David Lemon Dec 03 '18 at 12:50
  • 1
    This answer didn't support writing tags without storing the image on the local FS, nor did it not run standalone. But still! It solved my problem and I'm very happy! Bounty well earned, good sir! – thomax Dec 03 '18 at 14:45