Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I tell, ideally with an Imagemagick identify command, whether a particular PNG is PNG32, PNG24 or PNG8?

The %z or %[depth] gives the sample depth (not the pixel depth), which is always 8 or 16 regardless of PNG format, and %m or %[magick] just reports PNG.

share|improve this question
up vote 1 down vote accepted

In recent versions (6.6.9-2, of 2011-03-30, and later), "identify -verbose" outputs IHDR.bit_depth and IHDR.color_type:

identify -verbose g1.png | grep IHDR

png:IHDR.bit_depth : 1

png:IHDR.color_type : 0 (Grayscale)

or

identify -verbose png24.png | grep IHDR

png:IHDR.bit_depth : 8

png:IHDR.color_type : 2 (Truecolor)

or

identify -verbose png64.png | grep IHDR

png:IHDR.bit_depth : 16

png:IHDR.color_type : 6 (RGBA)

share|improve this answer
    
In what version was it introduced? – OrangeDog Dec 16 '15 at 15:33
    
@OrangeDog I added the feature to IM version 6.6.9-2, 2011-03-30 – Glenn Randers-Pehrson Dec 16 '15 at 15:56

To complete Kyle's answer, seems you have to use something like this (tested with IM 6.8.4):

#!/bin/sh

type=$(identify -verbose $1 | sed -n "s/^.*png:IHDR.color_type.*(\(.*\))$/\1/p")

case "$type" in
Indexed)
   depth=8
   ;;
Truecolor)
   depth=24
   ;;
RGBA)
   depth=32
   ;;
esac

echo $depth
share|improve this answer

Interesting question, -verbose outputs the IHDR.color_type value, more info here.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .