如何使用graphicsmagick在节点js中传输响应

时间:2013-04-07 21:57:49

标签: node.js express

我很难使用graphicmagic从nodejs返回图像。浏览器挂在流上。

我引用了NodeJS gm resize and pipe to response,但我仍然无法使其发挥作用。

gm = require('gm');

app.get('/text', function (req, res)
{
    gm(200, 400, "#ddff99f3")
    .drawText(10, 50, "from scratch")
    .stream('png', function (err, stdout, stderr) {
      stdout.pipe(res);
    });
});

2 个答案:

答案 0 :(得分:5)

您似乎没有设置适当的内容类型:

res.set('Content-Type', 'image/png'); // set the header here

在<{1}}

之前之前执行此操作

答案 1 :(得分:-1)

所以......呃,我只是重新启动机器,它神奇地工作了。