Using multer in memory buffer with GraphicsMagick

1.5k Views Asked by At

I'm trying to resize an image uploaded in memory, using multer over express to get the file. While I can access req.files.picture.buffer and it shows some content, when I pass the buffer to GM I receive a ENOENT. The code is as follows:

var buffer = req.files.picture.buffer

gm(buffer)
  .options({imageMagick: true})
  .resize(300)
  .toBuffer('PNG', function (err, buffer) {
    if (err) return handle(err);
      console.log('done!');
  });

return res.sendStatus(200);

Either using toBuffer or write as the output I get the same ENOENT. Am I missing something?

2

There are 2 best solutions below

0
On

There was some problem with my Linux setup and ImageMagick was not available to Node.js. After re-configuring the machine the code works without changes.

1
On

According to the gm Buffer example, you also need to supply a filename for the data. Example: gm(buffer, 'foo.jpg')