Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.