How to distinguish black and white photo using PHP
-
Assume that we are uploading a photo and we want to tell if it's a color image or black and white.
One way to find this out for JPEG and TIFF files is to use exif data of the photo.
-
Let $file be the variable that contains the path to the image file on the server. Then the line $exif = exif_read_data($file); will create an array $exif where exif data is stored.
-
If exists, array element $exif['COMPUTED']['IsColor'] contains data about the photo's color depth.
$exif['COMPUTED']['IsColor'] == 1 - photo is a color image
$exif['COMPUTED']['IsColor'] == 0 - photo is black and white