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.
Asked
Active
Viewed 1,018 times
0

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 Answers
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.
convert red.png \( gradient.png -resize 40% \) -gravity southeast -composite result.png
That gives this result:
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
-
Thanks @Mark,+1 for your answer , but I was looking for a solution for Node gm. – Saman Mohamadi Jul 05 '16 at 09:23
-
Another option may be to use **gm**'s `batch` command like I demonstrate in the second part of the answer here... http://stackoverflow.com/a/34123532/2836621 – Mark Setchell Jul 05 '16 at 09:46
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