[英]Write EXIF data to image stream Node.js
我找到了一个不错的 npm 包,它允许您将 Exif 数据读取和写入图像, https://github.com/Sobesednik/node-exiftool 。
我面临的挑战是它需要您提供图像的路径。 因此,如果您想使用此软件包修改 EXIF,则必须将映像写入磁盘。 是否有一种简单的方法来检查/读取 EXIF,并在必要时将 EXIF 数据写入图像流?
var imageURL = 'https://nodejs.org/static/images/logos/nodejs-new-pantone-black.png'
var upstreamServer = 'http://someupstreamserver/uploads'
request
.get(imageURL)
.pipe(
// TODO read EXIF
// TODO write missing EXIF
request
.post(upstreamServer, function(err, httpResponse, body){
res.send(201)
})
)
编辑:这个问题也被问到 node-exiftool
我有一个类似的任务。 我必须将物理尺寸和其他元数据写入 PNG 文件。 我找到了一些解决方案并将其合并到一个小型库中。 png-元数据
它可以从 NodeJS 缓冲区读取 PNG 元数据,并使用新元数据创建一个新缓冲区。
这是一个例子:
const buffer = fs.readFileSync('1000ppcm.png')
console.log(readMetadata(buffer));
withMetadata(buffer,{
clear: true, //remove old metadata
pHYs: { //300 dpi
x: 30000,
y: 30000,
units: RESOLUTION_UNITS.INCHES
},
tEXt: {
Title: "Short (one line) title or caption for image",
Author: "Name of image's creator",
Description: "Description of image (possibly long)",
Copyright: "Copyright notice",
Software: "Software used to create the image",
Disclaimer: "Legal disclaimer",
Warning: "Warning of nature of content",
Source: "Device used to create the image",
Comment: "Miscellaneous comment"
}
});
它可以修改为与流一起使用,例如,您可以实现 WritableBufferStream 类。
const { Writable } = require('stream');
/**
* Simple writable buffer stream
* @docs: https://nodejs.org/api/stream.html#stream_writable_streams
*/
class WritableBufferStream extends Writable {
constructor(options) {
super(options);
this._chunks = [];
}
_write(chunk, enc, callback) {
this._chunks.push(chunk);
return callback(null);
}
_destroy(err, callback) {
this._chunks = null;
return callback(null);
}
toBuffer() {
return Buffer.concat(this._chunks);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.