简体   繁体   English

请推荐一个用于将IPTC数据写入图像的Node模块?

[英]Please recommend a Node module for writing IPTC data to images?

I have a Node.js server whose job it is to download JPEG images, write certain data to a couple of IPTC fields (eg Iptc.Application2.Caption ) and pass the image on to another service.我有一个 Node.js 服务器,它的工作是下载 JPEG 图像,将某些数据写入几个 IPTC 字段(例如Iptc.Application2.Caption )并将图像传递给另一个服务。

Ideally, I'd like to write the IPTC data to the in-memory buffer (without writing the image to the local file system).理想情况下,我想将 IPTC 数据写入内存缓冲区(而不将图像写入本地文件系统)。 Failing that, I can live with a solution where I download, store the file to the FS, then apply the IPTC data.如果做不到这一点,我可以采用一种解决方案,在该解决方案中我下载、将文件存储到 FS,然后应用 IPTC 数据。

I've got this working with https://github.com/dberesford/exiv2node , but it doesn't work on Node.js v10.我已经使用https://github.com/dberesford/exiv2node 进行了这项工作,但它不适用于 Node.js v10。 And it depends on exiv2 C++ library which makes it messy to run containerized.而且它依赖于exiv2 C++ 库,这使得运行容器化变得很麻烦。

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?所以我的问题是:是否有一个像样的 Node.js 模块可以实现 IPTC 数据写入,并且不依赖于某些怪物 C 库?

I would use exiftool-vendored , that it just a wrapper for the exiftool command line utility .我会使用exiftool-vendored ,它只是exiftool 命令行实用程序的包装器。 It will also install the exiftool binary, if you have already installed exiftool you can use exiftool without this binary它还将安装 exiftool 二进制文件,如果您已经安装了 exiftool,则可以使用没有此二进制文件的 exiftool

Install exiftool:安装exiftool:

npm install --save exiftool-vendored

The tags you add are put in the specifications that supports them, in this case IPTC.您添加的标签被放入支持它们的规范中,在本例中为 IPTC。

For example I will add Artist and Copyright tags, and exiftool will put the correspondent IPTC tags.比如我会添加ArtistCopyright标签,exiftool 会放对应的 IPTC 标签。

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. exiftool.write将返回一个承诺,您可以在计算其他事情时等待。 More info on promises . 有关承诺的更多信息

Using the exiftool CLI you can check that the tags are well written to the file:使用 exiftool CLI,您可以检查标签是否正确写入文件:

$ 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
[...]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM