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 substitutetoBuffer(...
withwrite('asd.jpg', function(err) ...
it actually writes a proper file.
EDIT While writing this question I found the solution, see reply
Was facing the same problem, in my case: install the graphicsmagick binary.
sudo apt-get install graphicsmagick
setFormat('jpg')
caused the problems. Changing it tosetFormat('jpeg')
solved it.
Stream yields empty buffer
This indicates a general error of graphiksmagick. Here are some probable causes:
const gm = require('gm').subClass({imageMagick: true});
Feel free to add more ideas as comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With