Open In App

PHP | Imagick getImageColors() Function

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The Imagick::getImageColors() function is an inbuilt function in PHP which is used to get the number of unique colors in the image.

Syntax:  

int Imagick::getImageColors( void )

Parameters: This function does not accepts any parameters.

Return Value: This function returns an integer value which determines the number of unique colors in the image.

Errors/Exceptions: It throws an ImagickException on error.

Below program illustrates the Imagick::getImageColors() function in PHP:

Program:  

PHP
<?php
//require_once('path/vendor/autoload.php');

// Create an Imagick Object
$image = new Imagick(
"https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-14.png");

// getImageColors function
$size = $image->getImageColors();

// Display the unique color
print_r($size);
?>

Output: 

2955


Related Articles: 


Reference: https://www.php.net/manual/en/imagick.getimagecolors.php
 


Similar Reads