9

I am trying to pipe data from a stream into a child process.

var gm = spawn( 'gm convert - -thumbnail 220x165^ -gravity center -extent 220x165 thumb.jpg' );
var rs = fs.createReadStream( 'cow.jpg' );

rs.pipe( gm.stdin )

Do I need to call end on gm for it to work? Also in my real code I am getting the stream from a database.

Pickels
  • 33,902
  • 26
  • 118
  • 178

1 Answers1

11

Example of how to stream a request into imagemagick:

var image = request.get(req.params.url);
var size = req.params.size.split('x');
var args = ['-', '-thumbnail', req.params.size + '^', '-gravity', 'center', '-extent', req.params.size, '-' ];
var convert = spawn('convert', args);

image.pipe(convert.stdin);
convert.stdout.pipe(res);

Great talk about this: http://vimeo.com/43380478

And the source code: https://github.com/felixge/rebel-resize

Pickels
  • 33,902
  • 26
  • 118
  • 178
  • 1
    Do you know if it's possible to pipe multiple images into the child process? I'm trying to composite multiple image streams together and then have them piped out once composited. – NateW Oct 12 '15 at 00:35