[magick-users] Detecting transparency

Fred Weinhaus fmw at alink.net
Fri Feb 6 19:56:08 PST 2009


test for transparency as follows. if result is 1, then totally 
opaque, if result is 0, then totally transparent.
Thus any result less than 1 has some transparency.


transparency=`convert yourimage -resize 1x1 -alpha on -channel o 
-format "%[fx:u.a]" info:`

examples:

convert -size 100x100 xc:black -resize 1x1 -alpha on -channel o 
-format "%[fx:u.a]" info:
1

convert -size 100x100 xc:none -resize 1x1 -alpha on -channel o 
-format "%[fx:u.a]" info:
0

convert -size 100x100 gradient: -alpha copy -resize 1x1 -alpha on 
-channel o -format "%[fx:u.a]" info:
0.499992





More information about the Magick-users mailing list