【发布时间】:2014-10-16 04:19:11
【问题描述】:
我正在使用节点模块 gm,并且正在尝试识别 PNG 图像的大小。我制作了以下小程序来说明我的问题。如果您使用带文件名的 gm 构造函数,则会检索大小。如果您传递缓冲区 + 文件名提示,它将失败。
返回的错误是:
can't buffer image and identify size { [Error: Command failed: gm identify: No decode delegate for this image format ().
gm identify: Request did not return an image.
] code: 1, signal: null }
代码示例:
var fs = require('fs');
var gm = require('gm');
var buffer = fs.readFileSync('./test/test_image.png',{encoding:'binary'});
gm('./test/test_image.png').size(function(err,size) {
if (err) console.log("can't identify from disk read");
else {
gm(buffer,'test_image.png').size(function(err,size) {
if (err) console.log("can't buffer image and identify size");
else console.log("all good");
process.exit(0);
});
}
});
关于如何解决这个问题的任何想法?我的真实用例是从 web POST 端点获取 base64 编码的图像数据,因此从磁盘读取并不是一个真正的选择。
【问题讨论】: