【发布时间】:2014-07-15 16:13:22
【问题描述】:
我是 nodejs 的新手。在将图像发送到浏览器之前,我正在使用 graphicsmagick 来调整图像大小。 我的代码看起来像这样(res 是从 function(req,res){...} 发送的响应)-
imageURLPromise
.then(function(response) {
var body = response.body;
if (body) {
console.log("Found From: " + response.request.uri.href);
//set response headers here
setResponseData(res, response);
var buf = new Buffer(body, "binary");
console.log(buf);
//gm module
gm(buf).resize(400,300).toBuffer(function(err,buffer) {
console.log("buffer here");
res.end(buffer, "binary");
});
}
}, function(error) {
console.log(error);
});
我在浏览器中获取图像,我在此处获取日志“缓冲区”,但浏览器仍处于“加载”状态。
我曾尝试将 .stream() 与 gm 一起使用并将标准输出通过管道传输到响应,但它有同样的问题。
如果我取消 gm 并像这样直接将正文写入响应
res.end(body, 'binary');
然后它就可以正常工作了。
谁能告诉我这里做错了什么?
【问题讨论】:
标签: node.js imagemagick graphicsmagick