Search code examples
imageimagemagickimagemagick-convert

Imagemagic: How to create one image on another image with first image as background


I have two image files. I have a image where text is written on a white background. The second image is a prescription and i want to merge the second image on first image with first image set as background.

First Image

enter image description here

Second Image enter image description here

When i use below command i get below image

composite -geometry +100+20 firstImg.jpg secondImg.jpg finalImg.jpg

finalImage enter image description here

I want the text in the second image to be merged to the first image. I am new to image magic and is stuck with this. Thanks in advance.


Solution

  • Something like this:

    convert prescription.jpg \
     \( words.jpg -resize 300x -fuzz 10% -transparent white \) \
     -gravity center -geometry +0+80 -composite result.jpg
    

    enter image description here

    First I load the prescription template as a background, then I load and resize the words to the correct width, and then make the white (+/- 10%) areas transparent and overlay that onto the middle (-gravity center) with a small geometry offset to move it down little.

    I hope you are not being naughty.