Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do composite with gm node.js?

How to do 'gm composite -gravity center change_image_url base_image_url' with GM Node.js?

How to call gm().command() & gm().in() or gm().out() to achieve the above?

like image 915
Yvonne Avatar asked Aug 27 '13 10:08

Yvonne


2 Answers

After struggling for an hour, here is my solution for your question:

gm composite -gravity center change_image_url base_image_url

gm()
.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 :)

like image 105
ZeroHackeR Avatar answered Sep 27 '22 20:09

ZeroHackeR


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);
 });
like image 35
Ryan Wu Avatar answered Sep 27 '22 22:09

Ryan Wu