How to composite image with a mask

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
tczf1128
Posts: 28
Joined: 2018-12-04T22:47:49-07:00
Authentication code: 1152

How to composite image with a mask

Post by tczf1128 » 2019-01-29T23:24:04-07:00

mask image: Image

base image: Image

I want to make the base image into a circle with this mask image

version: IM-7

User avatar
fmw42
Posts: 25546
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to composite image with a mask

Post by fmw42 » 2019-01-30T00:22:05-07:00

You did not say which OS you are using nor the exact IM version. Assuming Unix (Linux or Mac OSX), try either

Code: Select all

magick base.jpg -set option:dims "%wx%h" \( mask.png -alpha extract -resize 200% -size "%[dims]" xc:white  +swap -gravity center -geometry -20-20 -alpha off -compose copy_opacity -composite \)  +geometry -compose over -composite result1.png

magick base.jpg -set option:dims "%wx%h" \( mask.png -alpha extract -resize 200% -size "%[dims]" xc:white  +swap -gravity center -geometry -20-20 -alpha off -compose copy_opacity -composite \)  +geometry -compose over -composite -trim +repage result2.png
For Windows, remove all the \

tczf1128
Posts: 28
Joined: 2018-12-04T22:47:49-07:00
Authentication code: 1152

Re: How to composite image with a mask

Post by tczf1128 » 2019-01-31T00:58:01-07:00

thanks!

Post Reply