I have some images with different formats (jpg, webp, png, …). I’m coding a script (in php) to gather some infos from these images (like dimensions, resolution, bit-depth and …).
Since with php built-in functions, just for jpg format (and maybe another format), it’s possible to obtain bit-depth property of an image; I tried Imagick functions to do so.
I tried this:
$image = new Imagick($tmpName);
$colorspace = $image->getImageColorspace();
$bitsPerChannel = $image->getImageDepth();
$channels = 0;
switch ($colorspace) {
case Imagick::COLORSPACE_SRGB:
$channels = 3;
break;
case Imagick::COLORSPACE_CMYK:
$channels = 4;
break;
case Imagick::COLORSPACE_GRAY:
$channels = 1;
break;
}
if ($image->getImageAlphaChannel()) {
$channels += 1; // add alpha
}
$totalBitsPerPixel = $bitsPerChannel * $channels;
But the value of $totalBitsPerPixel is different with “bit-depth” property which Windows shows in “Properties” of image.
I searched stackoverflow, googled all kind of functions, chatted with Sider(chrom), but couldn’t find the reason of this.
What I’m looking for is: Windows shows a bit-depth property for each image file. How to acquire that in php?
Giving advice would be appreciated.
I attached a sample image:
