I need to make two resized images from another one.
var fs = require('fs')
, gm = require('gm')
, async = require('async');
var worker = function(filename) {
img = gm(fs.createReadStream(filename));
img.flip();
this.run = function() {
async.series([
function(callback) {
img.resize(640, 480);
img.toBuffer(function(err, buffer) {
if (err) {
callback(err);
return;
}
callback(null, true);
})
},
function(callback) {
img.resize(320, 240);
img.toBuffer(function(err, buffer) {
if (err) {
callback(err);
return;
}
callback(null, true);
})
},
],
function(err, results) {
console.log(err, results);
});
};
}
new worker('test.jpg').run();
This code generates error:
Error: gm().stream() or gm().write() with a non-readable stream.
If I replace fs.createReadStream with a filename than everything works just fine. It looks like gm doesn't store the source image from stream in it's internal buffer. Is it a bug or I should know something else about using it in proper way?
Notice: Async is used because in real project I need both results to perform other actions with them.