PHP | imagecolorstotal() Function
Last Updated :
11 Jul, 2025
Improve
The imagecolorstotal() function is an inbuilt function in PHP which is used to find the number of colors in an image's palette. This function returns the number of colors in an image palette.
Syntax:
php
Output:
php
Output:
int imagecolorstotal ( $image )Parameters: This function accepts a single parameter $image which is mandatory. The imagecreatetruecolor() function is used to create an image in a given size. This function creates blank image of given size. Return Value: This function returns the number of colors in the given image palette or 0 for truecolor images. Below programs illustrate the imagecolorstotal() function in PHP: Program 1:
<?php
// store the image in variable.
$image = imagecreatefrompng(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png');
echo 'Colors in image: ' . imagecolorstotal($image);
// Free image
imagedestroy($image);
?>
Colors in image: 0Program 2:
<?php
// store the image in variable.
$image = imagecreatefromgif(
'https://media.geeksforgeeks.org/wp-content/uploads/animateImages.gif');
echo 'Colors in image: ' . imagecolorstotal($image);
// Free image
imagedestroy($image);
?>
Colors in image: 187Related Articles:
- PHP | imagecolorclosestalpha() Function
- PHP | imagecolorat() function
- PHP | imagecolorclosest() Function
Article Tags :