Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe stream to graphicsmagick/imagemagick child process

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.

like image 213
Pickels Avatar asked Apr 30 '12 15:04

Pickels


1 Answers

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

like image 180
Pickels Avatar answered Nov 10 '22 19:11

Pickels