Page 1 of 1

Clip PNG with an image mask

Posted: 2016-07-07T08:44:50-07:00
by be00k
I'm trying to clip an PNG image with an image mask.

I tried the following command:

Code: Select all

convert .\src.png .\mask.png -alpha Off -compose CopyOpacity -composite dst.png
When i use a JPEG as source image, everything is working fine. But if i use a PNG image, the output file turns black.

Source Image:
Image

Mask Image:
Image

Output:
Image

Anyone an idea what i'm doing wrong?

Re: Clip PNG with an image mask

Posted: 2016-07-07T08:50:07-07:00
by snibgo
You have "-alpha Off".

This turns off alpha in both images. What colour is revealed when you turn alpha off in the source image?

Re: Clip PNG with an image mask

Posted: 2016-07-12T03:54:24-07:00
by be00k
Ok, my fault! ;-) But if i remove the command "alpha -Off" the transparent part in the source image is getting black. So how can i preserve the transparency in the source image?

Re: Clip PNG with an image mask

Posted: 2016-07-12T05:37:33-07:00
by snibgo
You haven't said what result you want.

Your source has transparency. Your mask is greyscale. What pixels in the result should be transparent?

Re: Clip PNG with an image mask

Posted: 2016-07-12T08:07:50-07:00
by be00k
This is what i want to achieve:
Image


The transparent pixels in the source image should stay transparent

(Sorry for my vague descriptions before)

Re: Clip PNG with an image mask

Posted: 2016-07-12T09:11:35-07:00
by snibgo
This nearly gives what you want:

Code: Select all

convert src.png ( +clone -alpha extract mask.png -compose Darken -composite ) -compose CopyOpacity -composite out.png
It's not exact. Perhaps the offsets in src.png are not correct.