imageistruecolor() is an inbuilt function in PHP that is used to check if a given image is a true-color image or not. In a true-color image, each pixel is specified by the RGB (Red, Green, and Blue) color values.
Syntax
bool imageistruecolor(resource $image)
Parameters
imageistruecolor() takes a single parameter, $image. It holds the image.
Return Values
imageistruecolor() returns True if the given image is true-color or else, it returns False if the image is not a true-color image.
Example 1
<?php // Create an image instance with a true-color image using //imagecreatefrompng() function. $img = imagecreatefrompng('C:\xampp\htdocs\Images\img44.png'); // Checked if the image is true-color $istruecolor = imageistruecolor($img); // Show the output image to the browser if($istruecolor) { echo "The given input image is true-color"; } ?>
Output
// Input RGB image
// Resultant Output
The given input image is true-color.
Example 2
<?php // Create an image instance with a true-color image using //imagecreatefrompng() function. $img = imagecreatefrompng('C:\xampp\htdocs\Gray.png'); // Checked if the image is true-color $istruecolor = imageistruecolor($img); // Show the output image to the browser if($istruecolor) { echo "The given input image is not a true-color"; } ?>
Output
// An input gray color image.
// Output
The given input image is not a true-color image.