![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to ensure an image is a truecolor image using the imageistruecolor() function in PHP?
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.
Advertisements