如何使用graphicmagick在nodejs中传输响应

Tim*_*erz 3 node.js express

我使用graphicmagic从nodejs返回图像非常困难.浏览器挂在流上.

我已经引用了NodeJS gm调整大小和管道响应,但我仍然无法使其工作.

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);
    });
});
Run Code Online (Sandbox Code Playgroud)

tal*_*nes 5

看起来您没有设置适当的内容类型:

res.set('Content-Type', 'image/png'); // set the header here
Run Code Online (Sandbox Code Playgroud)

做到这一点之前调用gm.drawText