PHP | imageistruecolor() function

The imageistruecolor() function is an inbuilt function in PHP which is used to find whether an image is a true-color image or not. A true-color image is an image in which each pixel is specified by three values, ie, RGB.
Syntax:
bool imageistruecolor( resource $image )
Parameters:This function accepts a single parameter $image which holds the image.
Return Value: This function returns TRUE if image is truecolor or FALSE in other case.
Below given programs illustrate the imageistruecolor() function in PHP:
Program 1:
<?php // Create an image instance with a truecolor image $im = imagecreatefrompng( Â Â // Check if image is truecolor $istruecolor = imageistruecolor($im); Â Â // Show the output to browser if($istruecolor) { Â Â Â Â echo "The image is true color"; } ?> |
Output:
The image is true color
Program 2:
<?php // Create an image instance with a grayscale image $im = imagecreatefrompng( Â Â // Check if image is truecolor $istruecolor = imageistruecolor($im); Â Â // Show the output to browser if(!$istruecolor) { Â Â Â Â echo "The image is not true color"; } ?> |
Output:
The image is not true color
Reference: https://www.php.net/manual/en/function.imageistruecolor.php



