HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelTutorial Source codeReport an issue
Category
Example

get color count

← getColorAsString   getColorValue →
ImagickPixel::getColorCount appears to only work for ImagickPixel objects created through Imagick::getImageHistogram()


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()

ColorCount last pixel = 256244
Color is R 255 G 255 B 255
$imagick = new \Imagick();
$imagick->newPseudoImage(640, 480, "magick:logo");
$histogramElements = $imagick->getImageHistogram();
$lastColor = array_pop($histogramElements);
$color = $lastColor->getColor();
$output = sprintf(
    "ColorCount last pixel = %d\nColor is R %d G %d B %d",
    $lastColor->getColorCount(),
    $color['r'],
    $color['g'],
    $color['b']
);

return nl2br($output);