Greyscale PNG to Alpha Mask

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?".
Post Reply
alans

Greyscale PNG to Alpha Mask

Post by alans »

Hello,

I think that this is going to be a simple question to answer since I believe that I am missing a fundamental understanding on what format the alpha masks need to be in.

I'm having a heck of a time trying to create my own alpha mask from the following image. I want the outside of the box to be 100% transparent, the border to be opaque, and the inside to be slightly transparent:
Image

I want to apply the mask to this image:
Image

I have tried many different combinations of
• Dropping the depth of the alpha.png image.
• Removing the alpha of the alpha.png image.
• Converting the alpha.png image to another image format.
• Anything else I could find on forums that looked like it did what I wanted.

Can anyone let me know how I can convert the alpha.png image into a true alpha mask to use?

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

Re: Greyscale PNG to Alpha Mask

Post by fmw42 »

try

convert image.png alpha.png -alpha off -compose copy_opacity -composite result.png

but if you want to get rid of the slight halo around the white border, then you need to make sure that your black is completely black, which it is not currently.

convert image.png \( alpha.png -black-threshold 50% \) -alpha off -compose copy_opacity -composite result2.png

see
http://www.imagemagick.org/Usage/compose/#copyopacity
http://www.imagemagick.org/script/comma ... -threshold
alans

Re: Greyscale PNG to Alpha Mask

Post by alans »

Thanks!

This worked like a charm.
Post Reply