How to do composite with gm node.js?
After struggling for an hour, here is my solution for your question:
gm composite -gravity center change_image_url base_image_urlgm().command("composite") .in("-gravity", "center").in(change_image_url).in(base_image_url).write( output_file, function (err) { if (!err) console.log(' hooray! '); else console.log(err);});
Good luck! Hope it will be helpful to others as well :)
Install gm, (make sure you already install graphicsmagick
npm install gm
following is my example code to merge two image together (use gm.in
)
var gm = require('gm');gm() .in('-page', '+0+0') .in('bg.jpg') .in('-page', '+10+20') // location of smallIcon.jpg is x,y -> 10, 20 .in('smallIcon.jpg') .mosaic() .write('tesOutput.jpg', function (err) { if (err) console.log(err); });
i am doing that this way:
var exec = require('child_process').execvar command = [ '-composite', '-watermark', '20x50', '-gravity', 'center', '-quality', 100, 'images/watermark.png', 'images/input.jpg', //input 'images/watermarked.png' //output ]; // making watermark through exec - child_process exec(command.join(' '), function(err, stdout, stderr) { if (err) console.log(err); });