PHP | ImagickPixel getColorCount() function Last Updated : 31 Dec, 2019 Comments Improve Suggest changes Like Article Like Report The ImagickPixel::getColorCount() function is an inbuilt function in PHP which is used to get the color count associated with the pixel color. A color count is the number of pixels in the image that have the same color as this ImagickPixel. getColorCount() appears to only work for ImagickPixel objects created through getImageHistogram(). Syntax: int ImagickPixel::getColorCount( void ) : int Parameters: This function doesn’t accepts any parameter. Return Value: This function returns an integer containing the color count. Exceptions: This function throws ImagickException on error. Below given programs illustrate the ImagickPixel::getColorCount() function in PHP: Program 1: php <?php // Create a new imagick object $imagick = new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Get the image histogram $histogramElements = $imagick->getImageHistogram(); // Get the last index $lastIndex = count($histogramElements) - 1; // Get the element from array which is // a ImagickPixel object $lastColor = $histogramElements[$lastIndex]; // Get the Color count echo $lastColor->getColorCount(); ?> Output: 18 Program 2: php <?php // Create a new imagick object $imagick = new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Get the image histogram $histogramElements = $imagick->getImageHistogram(); // Get the element from array which is // a ImagickPixel object $lastColor = $histogramElements[0]; // Get the Color count echo $lastColor->getColorCount(); ?> Output: 1 Program 3: php <?php // Create a new imagick object $imagick = new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Get the image histogram $histogramElements = $imagick->getImageHistogram(); // Get the element from array which is // a ImagickPixel object $firstColor = $histogramElements[0]; // Set the Color count $firstColor->setColorCount(20); // Get the Color count echo $firstColor->getColorCount(); ?> Output: 20 Program 3: php <?php // Create a new imagick object $imagick = new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Get the image histogram $histogramElements = $imagick->getImageHistogram(); // Get the whole color stats echo "R G B Hue :Count<br>"; foreach ($histogramElements as $pixel) { $colors = $pixel->getColor(); foreach ($colors as $color) { print($color . " "); } print(":" . $pixel->getColorCount() . "<br>"); } ?> Output: R G B Hue :Count 0 22 35 1 :1 0 25 37 1 :1 0 24 37 1 :1 0 31 43 1 :1 0 32 44 1 :1 0 33 45 1 :1 0 37 49 1 :3 . . . Reference: https://www.php.net/manual/en/imagickpixel.getcolorcount.php Comment More infoAdvertise with us Next Article PHP | ImagickPixel getColorCount() function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Imagick Similar Reads PHP | GmagickPixel getcolorcount() Function The GmagickPixel::getcolorcount() function is an inbuilt function in PHP which is used to get the color count associated with the pixel color. A color count is the number of pixels in the image that have the same color as this GmagickPixel. The getcolorcount() appears to only work for GmagickPixel o 2 min read PHP | ImagickPixel getColor() Function The ImagickPixel::getColor() function is an inbuilt function in PHP which is used to get the color described by the ImagickPixel object, as an array. If the color has an opacity channel set, this is provided as a fourth value in the list. Keys of the array are r is (red), b is (blue), g is (green) a 2 min read PHP | ImagickPixel getColorQuantum() Function The ImagickPixel::getColorQuantum() function is an inbuilt function in PHP which is used to get the color of the pixel in an array as Quantum values. This function returns an array with keys r, g, b and an each stands for red, green, blue and alpha/opacity respectively. Quantum value ranges from 0 t 2 min read PHP | ImagickPixel getColorValue() function The ImagickPixel::getColorValue() function is an inbuilt function in PHP which is used to get the normalized value of the provided color channel for a given ImagickPixel's color. The normalized value is a floating-point number between 0 and 1. Syntax: float ImagickPixel::getColorValue( int $color ) 1 min read PHP | GmagickPixel getcolor() Function The GmagickPixel::getcolor() function is an inbuilt function in PHP which is used to get the color described by the GmagickPixel object, as a string or an array. If the color has an opacity channel set, this is provided as a fourth value in the list. Syntax: mixed GmagickPixel::getcolor( bool $as_ar 2 min read PHP | ImagickPixel getColorValueQuantum() function The ImagickPixel::getColorValueQuantum() function is an inbuilt function in PHP which is used to get the normalized value of the provided color channel for a given ImagickPixel's color. The normalized value lies in the quantum range where 65535 is maximum and 0 is lowest on contrary to getColorValue 2 min read PHP | GmagickPixel getcolorvalue() Function The GmagickPixel::getcolorvalue() function is an inbuilt function in PHP which is used to get the normalized value of the provided color channel for a given GmagickPixel color. The normalized value is a floating-point number between 0 and 1. Syntax: float GmagickPixel::getcolorvalue( int $color ) Pa 2 min read PHP | ImagickPixel getHSL() function The ImagickPixel::getHSL() function is an inbuilt function in PHP which is used to get the normalized HSL color described by the ImagickPixel object, with each being floating-point numbers between 0 and 1. HSL stands for hue, saturation, and luminosity. In general, hue decides what color is of the p 1 min read PHP | Imagick getColorspace() Function The Imagick::getColorspace() function is an inbuilt function in PHP which is used to get the global colorspace value of an image. Syntax: int Imagick::getColorspace( void ) Parameters: This function doesn't accept any parameters. Return Value: This function returns an integer value which can be comp 1 min read PHP | ImagickPixel getIndex() function The ImagickPixel::getIndex() function is an inbuilt function in PHP which is used to get the colormap index of the pixel. Syntax: int ImagickPixel::getIndex( void ) Parameters:This function doesnât accept any parameter. Return Value: This function returns an integer value containing the index. Excep 2 min read Like