general transparency and color full transparency

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
manuxio
Posts: 2
Joined: 2011-07-22T06:20:54-07:00
Authentication code: 8675308

general transparency and color full transparency

Post by manuxio »

Hello all,
sorry for posting a maybe-stupid question,
but I need to convert an image to PNG and I want the result to:

- have FULL transparency on white
- have general 50% transparency on the rest

All I have available is ImageMagick 6.3.2 (can't upgrade)
so I managed to:

convert Atoll.bmp -matte -channel a -evaluate set 50% transparentmap.png (this works, and gives 50% transparency on the whole image)
but I tried to make white full transparent by
convert Atoll.bmp -transparent white -matte -channel a -evaluate set 50% -transparent white transparentmap.png (this does exactly as above, white is still visible with 50% general transparency).

Can you please correct my command?

Thank you
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: general transparency and color full transparency

Post by anthony »

The problem is that your white is no longer white! It is now semi-transparent white! As such it no longer matches.

If your image is fully-opaque everywhere, I have a simple solution...
first make white fully-transparent. Then multiple the alpha channel by 50%, (using -evaluate) anything fully transparent will then remain fully transparent, anything else will be 50% transparent.

If the image is not fully-opaque, then you may need to make a mask of the white areas, do the 50% transparent, then use that mask to make white areas transparent.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
manuxio
Posts: 2
Joined: 2011-07-22T06:20:54-07:00
Authentication code: 8675308

Re: general transparency and color full transparency

Post by manuxio »

I was on my way to realize that :)

what do you think about this?
(I know the pixel at 0,0 is the background...)

convert Atoll.bmp -matte -channel a -evaluate set 50% transparentmap.png
color=`convert transparentmap.png -format "%[pixel: u.p{0,0}]" info:`
convert transparentmap.png -transparent $color transparentmap.png

but since I also know it originally is white,
can you help me out doing it the correct way?
First full transparency, then 50%?

Can this be done in one line?

Edit:
tried this:
convert Atoll.bmp -transparent white -matte -channel a -evaluate set 50% transparentmap.png
but with no success :(


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

Re: general transparency and color full transparency

Post by fmw42 »

try this, here I use the IM internal image logo:

make white transparent
extract the alpha channel and map white to midgray
put the modified alpha channel back in place of the first one that only has white as transparent


convert \( logo: -transparent white \) \
\( +clone -alpha extract -fill "gray(50%)" -opaque white \) \
-alpha off -compose copy_opacity -composite logo_tmp.png

On older systems, you may have to do it this way:

convert \( logo: -transparent white \) \
\( +clone -channel o -separate +channel -negate -fill "gray(50%)" -opaque white \) \
-alpha off -compose copy_opacity -composite logo_tmp.png


the above is unix, if on windows, parens don't need escaping with \ and the line feed escape character is ^. See http://www.imagemagick.org/Usage/windows/
Post Reply