Saman Mohamadi
Saman Mohamadi

Reputation: 4672

Node Js gm, Resize and overlap

I want to insert an image(img1) into another(img2) but before inserting, img1 must be resized based on img2 dimensions.
how can I achieve this with nodeJs gm ?
I'm using imageMagic.

Upvotes: 0

Views: 1066

Answers (2)

Ahmet Cetin
Ahmet Cetin

Reputation: 3823

I just found solution, and answered my own question here: Resize and compose two or more images using gm in Nodejs, but here I post for your convenience:

gm()
.in('-geometry', '+0+0')
.in('./img/img1.png')
.in('-geometry', '300x300+100+200')
.in('./img/img2.png')
.flatten()
.write('resultGM.png', function (err) {
  if (err) console.log(err);
});

Upvotes: 0

Mark Setchell
Mark Setchell

Reputation: 208077

I don't speak node, but here is how you might do it at the command-line. I'll use these two images, both the same size at 200x100.

enter image description here enter image description here

convert red.png \( gradient.png -resize 40% \) -gravity southeast -composite result.png

That gives this result:

enter image description here

To translate that into node, you need to look at Eric's (@emcconville) answer here. I don't believe GraphicsMagick supports the parentheses syntax, so I guess you will need to use the more sophisticated ImageMagick.

Upvotes: 2

Related Questions