Tuesday, June 9, 2026
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
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6895 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS