0

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.

3 Answers 3

1

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)

2
  • In what version was it introduced?
    – OrangeDog
    Dec 16, 2015 at 15:33
  • @OrangeDog I added the feature to IM version 6.6.9-2, 2011-03-30 Dec 16, 2015 at 15:56
2

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
0

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

You must log in to answer this question.

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