gpt4 book ai didi

javascript - 将 EXIF 数据写入图像流 Node.js

转载 作者:行者123 更新时间:2023-12-03 11:24:06 28 4
gpt4 key购买 nike

我找到了一个不错的 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-metadata

它可以从 NodeJS Buffers 中读取 PNG 元数据,并使用新的元数据创建一个新的 Buffers。

这是一个例子:

        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);
}
}

关于javascript - 将 EXIF 数据写入图像流 Node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43301126/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com