Imagick::getImageHistogram

(PECL imagick 2, PECL imagick 3)

Imagick::getImageHistogramRetourne l'histogramme de l'image

Description

publicImagick::getImageHistogram(): array

Retourne l'histogramme de l'image, sous forme d'un tableau d'objets ImagickPixel.

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Retourne un tableau d'objets ImagickPixel. Émet une exception ImagickException en cas d'échec.

Erreurs / Exceptions

Lance une exception ImagickException si une erreur survient.

Exemples

Exemple #1 Exemple avec Imagick::getImageHistogram()

<?php
function getColorStatistics($histogramElements, $colorChannel) {
$colorStatistics = [];

foreach (
$histogramElements as $histogramElement) {
$color = $histogramElement->getColorValue($colorChannel);
$color = intval($color * 255);
$count = $histogramElement->getColorCount();

if (
array_key_exists($color, $colorStatistics)) {
$colorStatistics[$color] += $count;
}
else {
$colorStatistics[$color] = $count;
}
}

ksort($colorStatistics);

return
$colorStatistics;
}



function
getImageHistogram($imagePath) {

$backgroundColor = 'black';

$draw = new \ImagickDraw();
$draw->setStrokeWidth(0); // en rend les lignes le plus fin possible

$imagick = new \Imagick();
$imagick->newImage(500, 500, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->drawImage($draw);

$histogramWidth = 256;
$histogramHeight = 100; // la hauteur de chaque segment RGB

$imagick = new \Imagick(realpath($imagePath));
//Resize the image to be small, otherwise PHP tends to run out of memory
To Top