php8.5
Home/ Manual/ imagick / imagickpixel/ ImagickPixel::getColorCount

ImagickPixel::getColorCount

PHP function Edit on GitHub ✎

(PECL imagick 2, PECL imagick 3)

Returns the color count associated with this color

Description

ImagickPixel::getColorCount(): int

Returns the color count associated with this color.

The color count is the number of pixels in the image that have the same color as this ImagickPixel.

ImagickPixel::getColorCount appears to only work for ImagickPixel objects created through Imagick::getImageHistogram()

Parameters Parameters

Return Values

Returns the color count as an integer on success, throws ImagickPixelException on failure.

Examples

ImagickPixel getColorCount()

php
<?php
    $imagick = new \Imagick();
    $imagick->newPseudoImage(640, 480, "magick:logo");
    $histogramElements = $imagick->getImageHistogram();
    $lastColor = array_pop($histogramElements);
    echo "Last pixel color count is: ".$lastColor->getColorCount();
?>

The output for this will be similar to:

output
Last pixel color count is: 256244

Source: reference/imagick/imagickpixel/getcolorcount.xml · from the official PHP manual (php/doc-en)