22

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

6 Answers 6

16

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

sudo apt-get install graphicsmagick

Sign up to request clarification or add additional context in comments.

1 Comment

Same here. brew install graphicsmagick on Mac (if you've got Homebrew installed)
10

Stream yields empty buffer

This indicates a general error of graphiksmagick. Here are some probable causes:

  1. Missing Installation: you did not install graphicsmagick or imagemagick correctly. Make sure you installed both and
  2. Invalid Parameter: remove all parameters until it works. jpg instead of jpeg is a common mistake
  3. Wrong library You made use of graphicmagick but wanted to use imagemagick? (e.g. for webp conversion). Add imageMagick configuration:

const gm = require('gm').subClass({imageMagick: true});

Feel free to add more ideas as comment.

1 Comment

The Missing Installation point solved it for me—I didn't read the ReadMe and didn't realise that you had to also have GraphicsMagick installed separately. Thanks!
9

setFormat('jpg')
caused the problems. Changing it to
setFormat('jpeg') solved it.

1 Comment

Can also add extension as an argument .toBuffer('jpeg', (error, buffer) => to avoid the setFormat line.
4

I also stumbled upon this error. For me the solution was to increase the allowed memory from 128Mb to 256Mb. I noticed the process needed 137Mb in order to succeed.

2 Comments

How do you do that? Was this the node process or the imagemagick process?
It was the lambda process itself.
2

Error: Stream yields empty buffer

For me the solution of the error was to install both graphicsmagick and imagemagick.

Maybe it is because I use the app in node-alpine container and I want to use only graphicsmagick functionality of gm.

1 Comment

Same issue here. Worked after.
0

The issue even if you have installed it in your node project (let's say using npm) then also you need to have the actual graphics processing binaries installed on your system!
brew install graphicsmagick

So, if it works locally for you make sure to install it on the prod server as well

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.