Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
be00k
Posts: 3 Joined: 2016-07-07T07:57:22-07:00
Authentication code: 1151
Post
by be00k » 2016-07-07T08:44:50-07:00
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:
Mask Image:
Output:
Anyone an idea what i'm doing wrong?
snibgo
Posts: 12159 Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Post
by snibgo » 2016-07-07T08:50:07-07:00
You have "-alpha Off".
This turns off alpha in both images. What colour is revealed when you turn alpha off in the source image?
be00k
Posts: 3 Joined: 2016-07-07T07:57:22-07:00
Authentication code: 1151
Post
by be00k » 2016-07-12T03:54:24-07:00
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?
snibgo
Posts: 12159 Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Post
by snibgo » 2016-07-12T05:37:33-07:00
You haven't said what result you want.
Your source has transparency. Your mask is greyscale. What pixels in the result should be transparent?
be00k
Posts: 3 Joined: 2016-07-07T07:57:22-07:00
Authentication code: 1151
Post
by be00k » 2016-07-12T08:07:50-07:00
This is what i want to achieve:
The transparent pixels in the source image should stay transparent
(Sorry for my vague descriptions before)
snibgo
Posts: 12159 Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Post
by snibgo » 2016-07-12T09:11:35-07:00
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.