node.js - nodejs gm using stream twice -


i need make 2 resized images 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() non-readable stream. 

if replace fs.createreadstream filename works fine. looks gm doesn't store source image stream in it's internal buffer. bug or should know else using in proper way?

notice: async used because in real project need both results perform other actions them.

try this, dont think need use writestreams in case:

gm(imagepath)   .resize(640, 480)   .autoorient()   .flip()   .write(newimagepath, function(e) {   if (e) throw e;   gm(newimagepath)     .resize(320, 240)     .write(newimagepathsmall, function(e) {     if (e) throw e;     console.log('resized successfuly');   }); }); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -