jordi wrote: ↑2018-04-19T04:31:01-07:00I want to merge 2 images by using a mask so I will have :
1.- original image a.jpg ( background )
2.- new image b.jpg ( over the background)
3.- mask image mask.jpg
[...]
Any code sample on how to get to point 4 ?
would that work equally with a mask that has a gradient ?
When you have a question here you need to give us more information. At the very least you should always let us know which version of IM you're using and what platform or OS you're working on. The answers can be a bit different – or a lot – depending on your set-up. Read the instructions
at THIS link to learn how to form a proper question.
That said, the simplest composition with a mask should work with a command like this...
Code: Select all
convert image1.png image2.png mask.png -composite result.png
The white areas of your mask will determine which parts of the overlay image will be composited onto the background image. To see how it works with a gradient mask, try this experiment...
Code: Select all
convert image1.png image2.png \( mask.png -blur 0x10 \) -composite result2.png
That isolates the mask image within the parentheses and applies a blur, then composites the overlay with a a softened edge determined by the blur of the mask.
The command above is in *nix shell command syntax. To use the same command in Windows CMD you need to remove the backslashes that escape the parentheses. Change this "\(...\)" to this "(...)". If you're using ImageMagick v7, use "magick" instead of "convert".
The page
at THIS link describes the usage of the "-composite" operator in detail.