GraphicsMagick: toBuffer() Stream yields empty buffer

Bernhardt Scherer picture Bernhardt Scherer · Feb 16, 2016 · Viewed 13k times · Source

I am trying to read a file into a buffer, resize it and then write it to disk using the following example code:

function processImage(data) {
gm(data, 'test.jpg')
    .resize('300x300')
  .background('white')
  .flatten()
  .setFormat('jpg')
  .toBuffer(function(err, buffer) {
    if (err) {
        throw err;
    } else {
        fs.writeFile('asd.jpg', buffer);
    }
  });
}

However, this generates an error Error: Stream yields empty buffer. I have played around, used imageMagick and graphicsMagick, still the same.

If i substitute
toBuffer(...
with
write('asd.jpg', function(err) ...

it actually writes a proper file.

EDIT While writing this question I found the solution, see reply

Answer

Edo picture Edo · Sep 30, 2016

Was facing the same problem, in my case: install the graphicsmagick binary.

sudo apt-get install graphicsmagick