How to use mask and combine 2 images into 1 using imageMagick?

433 views Asked by At

I have a JPEG template:

template image

I need put a JPEG image inside that grey mask and save it as a JPEG. (so resize the jpeg, and put it where the greay mask is).

Is there a way to do that using php and imagemagick extension ?

Regards

1

There are 1 answers

0
T-Dor On BEST ANSWER

If you want your image to be 318px x 235px (to fit in the window of your template), you can resize using ImageMagick:

convert photo-big.jpg -resize '318x235^' photo-small.jpg 

The ^ insures that the small version will not be any smaller than the given dimensions, although one dimension may be bigger, in order to maintain the aspect ratio.

In order to insert the resized image into your template, you'll need a third image to serve as a mask. The mask is only black and white: the white is where you want the photo to show up in your template, like this: mask for template

Use the following line of code to create your composite image. The geometry indicates the offset in pixels (59 down and 15 over) to position the photo in the window:

composite -geometry '+15+59' photo-small.jpg template.jpg mask.jpg comp.jpg