Search code examples
image-processingimagemagickimagemagick-convert

Get specific channel depth with ImageMagick


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


Solution

  • 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.