Page 1 of 1

Remove png image using mask

Posted: 2017-06-19T11:41:10-07:00
by filipemansano
Hi, i need remove part of image using mask (black and white)
my original image is a PNG image no-background, using mask i need to keep white area and remove black area

i try

Code: Select all

convert original.png mascara.png -alpha off -compose CopyOpacity -composite out.png
this command remove using mask ,But the end result is coming up with a black background

Original image: https://ibb.co/kFZwoQ
Mask image: https://ibb.co/dtuCTQ
Result: https://ibb.co/dGfxv5

How do I remove using the mask, but keeping the background transparent?

Re: Remove png image using mask

Posted: 2017-06-19T11:55:35-07:00
by fmw42
Your original.png image has transparency. So you need to combine the transparency of the original.png and mascara.png. You have not said what version of IM you have nor your platform. Please always provide that when asking questions.

In Unix:

Code: Select all

convert original.png mascara.png \
\( -clone 0 -alpha extract \) \
\( -clone 1,2 -compose multiply -composite \) \
-delete 1,2 -alpha off -compose over -compose copy_opacity -composite result.png
In Windows:

Code: Select all

convert original.png mascara.png ^
( -clone 0 -alpha extract ) ^
( -clone 1,2 -compose multiply -composite ) ^
-delete 1,2 -alpha off -compose over -compose copy_opacity -composite result.png
I have split the command into multiple lines, so if you copy and past, be sure that there are no spaces after the ending characters / or ^, depending upon your OS.

For one long line of code:

In Unix:

Code: Select all

convert original.png mascara.png \( -clone 0 -alpha extract \) \( -clone 1,2 -compose multiply -composite \) -delete 1,2 -alpha off -compose over -compose copy_opacity -composite result.png
In Windows:

Code: Select all

convert original.png mascara.png ( -clone 0 -alpha extract ) ( -clone 1,2 -compose multiply -composite ) -delete 1,2 -alpha off -compose over -compose copy_opacity -composite result.png

Re: Remove png image using mask

Posted: 2017-06-19T15:04:40-07:00
by filipemansano
worked perfectly!
Sorry, I really forgot to tell the version.

SO: Windows
Version: ImageMagick 7.0.6-0 Q16 x64 2017-06-11

thank you again

Re: Remove png image using mask

Posted: 2017-06-19T15:09:10-07:00
by fmw42
For IM 7, change convert to magick