From these articles I wrote a simple function than can give you the color type of a PNG file:
https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html
In short: A PNG file is composed of a header and chunks. In the header from second the forth byte should be ASCII string equal to "PNG", then the chunks which names are 4 bytes follow. The IHDR chunk gives you some data about the image like with, height and the needed color type. This chunk's position is always fixed as it is always the first chunk. And it's content is described in the second link I gave you:
The IHDR chunk must appear FIRST. It contains:
Width: 4 bytes
Height: 4 bytes
Bit depth: 1 byte
Color type: 1 byte
Compression method: 1 byte
Filter method: 1 byte
Interlace method: 1 byte
So knowing the length of the header, length of the chunk name and it's structure we can calculate the position of the color type data and it's the 26 byte. Now we can write a simple function that reads the color type of a PNG file.
function getPNGColorType($filename)
{
$handle = fopen($filename, "r");
if (false === $handle) {
echo "Can't open file $filename for reading";
exit(1);
}
//set poitner to where the PNG chunk shuold be
fseek($handle, 1);
$mime = fread($handle, 3);
if ("PNG" !== $mime) {
echo "$filename is not a PNG file.";
exit(1);
}
//set poitner to the color type byte and read it
fseek($handle, 25);
$content = fread($handle, 1);
fclose($handle);
//get integer value
$unpack = unpack("c", $content);
return $unpack[1];
}
$filename = "tmp/png.png";
getPNGColorType($filename);
Here is the color type nomenclature (from the second link):
Color Allowed Interpretation
Type Bit Depths
0 1,2,4,8,16 Each pixel is a grayscale sample.
2 8,16 Each pixel is an R,G,B triple.
3 1,2,4,8 Each pixel is a palette index;
a PLTE chunk must appear.
4 8,16 Each pixel is a grayscale sample,
followed by an alpha sample.
6 8,16 Each pixel is an R,G,B triple,
I hope this helps.