Page 1 of 1

Crop image using a black/white mask

Posted: 2011-04-28T02:00:47-07:00
by canduc17
Hi everyone.

I have 2 png images of the same size and one of them is a mask: a white circle in the center with every other pixels black.
I would like to obtain a cropped image with the original one substituting the white circle and with the other pixels black.

I've tried with this tutorial, typing

Code: Select all

convert mask.png orig.png -compose ChangeMask  -composite  cropped.png
but I've obtained an image equal to the mask.

Have you got any suggestions?

Thanks in advance!

Re: Crop image using a black/white mask

Posted: 2011-04-28T09:40:37-07:00
by fmw42
try either of these (assuming your mask is a white circle surrounded by black)

convert mask.png image.png mask.png -compose multiply -composite result.png

convert image.png mask.png -compose copy_opacity -composite -compose over -background black -flatten result.png

Re: Crop image using a black/white mask

Posted: 2011-04-28T16:46:36-07:00
by anthony
See IM Examples, Masking, Mathematical and Alpha Composition
http://www.imagemagick.org/Usage/masking/#compose