Monday, September 15, 2025
HomeLanguagesPHP | imageistruecolor() function

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

RELATED ARTICLES

Most Popular

Dominic
32288 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6654 POSTS0 COMMENTS
Nicole Veronica
11823 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11887 POSTS0 COMMENTS
Shaida Kate Naidoo
6770 POSTS0 COMMENTS
Ted Musemwa
7039 POSTS0 COMMENTS
Thapelo Manthata
6726 POSTS0 COMMENTS
Umr Jansen
6736 POSTS0 COMMENTS