3

I am having a really difficult time returning an image from nodejs using graphicmagic. The browser is hung on the stream.

I have referenced NodeJS gm resize and pipe to response but I still can't make it work.

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);
    });
});
1
  • 2
    I have missed the 'png' parameter. You have saved my day.
    – user1021364
    Mar 26, 2016 at 13:53

2 Answers 2

5

Looks like you aren't setting the appropriate Content-type:

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

Do this before the call to gm.drawText

-1

so...uh, I just rebooted my machine and it magically worked.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.