0

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.

Saman Mohamadi
  • 4,454
  • 4
  • 38
  • 58
  • Load both images, get the dimensions of image2, resize image1 accordingly then composite it on top of image2 and save. – Mark Setchell Jul 03 '16 at 21:11
  • Is there any way that no need for saving resized version of image1? Becuse there are some other steps and I want these steps to be done on the fly. – Saman Mohamadi Jul 04 '16 at 06:34

2 Answers2

2

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.

Community
  • 1
  • 1
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
0

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);
});
Community
  • 1
  • 1
Ahmet Cetin
  • 3,683
  • 3
  • 25
  • 34