Page 1 of 1

general transparency and color full transparency

Posted: 2011-07-22T06:26:59-07:00
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

Re: general transparency and color full transparency

Posted: 2011-07-22T06:49:10-07:00
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.

Re: general transparency and color full transparency

Posted: 2011-07-22T07:03:25-07:00
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

Re: general transparency and color full transparency

Posted: 2011-07-22T10:01:12-07:00
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/