node.js - Graphicsmagick for node not writing the jpg -


i using https://github.com/aheckmann/gm resize image.

    var gm = require('gm').subclass({ imagemagick: true });     var fs = require('fs');      var dir = __dirname+'/img';      var readstream = fs.createreadstream(dir + '/desert.jpg');     var writestream = fs.createwritestream(dir + '/resize.jpg');       gm(readstream)         .size({bufferstream: true}, function(err, size) {             this.resize(50, 50, '%')                     this.write(writestream, function (err) {             if (!err) console.log('done');         });      }); 

i using above code resize image....the problem empty image getting generated , error message {[error: write epipe] code:'epipe',errno: 'epipe', syscall:'write'}

write method takes string output filename. try stream method:

gm(readstream) .size({bufferstream: true}, function(err, size) {     this.resize(50, 50, '%')             .stream()     .on('end',function(){         console.log('done');     })     .on('error',function(err){         console.log(err);     })     .pipe(writestream); }); 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -