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
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS