0
votes

Is it possible to get the bit depth of a specific channel with an ImageMagick command?

I can see the individual channel depths with convert :rose -verbose info:, but I was wondering if there was a trick to only getting to print the alpha depth.

The reason I'm doing this is because I'm trying to write a script to figure out if an image either:

  • Does not support transparency (like JPEG)
  • Only supports ON/OFF transparency (like GIF)
  • Supports >1 bit transparency (like PNG)

I can check if the image is fully opaque with identify %[opaque] :rose, and was thinking I could check the type of transparency by checking if the alpha bit depth is greater than 1

2

2 Answers

1
votes

In Imagemagick to get the bit depth of the alpha channel, try

convert transparent_image -alpha extract -format "%z\n" info:

or

convert transparent_image -alpha extract -format "%[depth]\n" info:

See http://www.imagemagick.org/script/escape.php

For example:

convert logo: -transparent white -alpha extract -format "%z" info:

8

However, this may actually be binary, but listed as 8-bits.

So you might want to look at the histogram or unique-colors to see how many actual colors exist.

convert logo: -transparent white -alpha extract -format "%[colors]\n" info:

2

1
votes

Through some agonizing searching and trial and error, I may have figured it out. If I run

convert rose: -channel A -separate -format %[fx:z] info:-

I get the number of bits in the alpha channel. For PNGs it seems to print 8, for JPEGs and GIFs it prints 1.