问题描述
我有一个Node.js服务器,它的工作是下载JPEG图像,将某些数据写入几个IPTC字段(例如 Iptc.Application2.Caption
),然后将图像传递给另一个服务.
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.
理想情况下,我想将IPTC数据写入内存中的缓冲区(而不是将映像写入本地文件系统).失败的话,我可以使用一种解决方案,在该解决方案中下载,将文件存储到FS,然后应用IPTC数据.
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.
我已经与 https://github.com/dberesford/exiv2node 一起使用了,但不适用于Node.js v10.而且它依赖于 exiv2 C ++库,这使得运行容器化变得很混乱.
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.
所以我的问题是:是否有一个不错的Node.js模块可以启用IPTC数据写入,并且不依赖于某些怪物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?
推荐答案
我会使用 exiftool-vendored,它只是 exiftool命令行实用程序的包装.它还将安装exiftool二进制文件,如果您已经安装了exiftool,则可以使用不带该二进制文件的 exiftool
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
安装exiftool:
Install exiftool:
npm install --save exiftool-vendored
您添加的标签将放入支持它们的规范中,在本例中为IPTC.
The tags you add are put in the specifications that supports them, in this case IPTC.
例如,我将添加 Artist 和 Copyright 标签,而exiftool将放置相应的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
将返回一个承诺,您可以在计算其他内容时等待.有关承诺的更多信息
exiftool.write
will return a promise that you can wait for while computing another things. More info on promises.
使用exiftool CLI,您可以检查标签是否正确写入文件:
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
[...]
这篇关于请推荐用于将IPTC数据写入图像的Node模块吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!