Geen cache-versie.


Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

Rechercher une fonction PHP

Imagick::getImageHistogram

(PECL imagick 2.0.0)

Imagick::getImageHistogramGets the image histogram

Description

Imagick::getImageHistogram ( void ) : array

Returns the image histogram as an array of ImagickPixel objects.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Return Values

Returns the image histogram as an array of ImagickPixel objects.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Errors/Exceptions

Throws ImagickException on error.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Examples

Example #1 Generates 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); //make the lines be as thin as possible

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

    
$histogramWidth 256;
    
$histogramHeight 100// the height for each RGB segment

    
$imagick = new \Imagick(realpath($imagePath));
    
//Resize the image to be small, otherwise PHP tends to run out of memory
    //This might lead to bad results for images that are pathologically 'pixelly'
    
$imagick->adaptiveResizeImage(200200true);
    
$histogramElements $imagick->getImageHistogram();

    
$histogram = new \Imagick();
    
$histogram->newpseudoimage($histogramWidth$histogramHeight 3'xc:black');
    
$histogram->setImageFormat('png');

    
$getMax = function ($carry$item)  {
        if (
$item $carry) {
            return 
$item;
        }
        return 
$carry;
    };

    
$colorValues = [
        
'red' => getColorStatistics($histogramElements, \Imagick::COLOR_RED),
        
'lime' => getColorStatistics($histogramElements, \Imagick::COLOR_GREEN),
        
'blue' => getColorStatistics($histogramElements, \Imagick::COLOR_BLUE),
    ];

    
$max array_reduce($colorValues['red'] , $getMax0);
    
$max array_reduce($colorValues['lime'] , $getMax$max);
    
$max array_reduce($colorValues['blue'] , $getMax$max);

    
$scale =  $histogramHeight $max;

    
$count 0;
    foreach (
$colorValues as $color => $values) {
        
$draw->setstrokecolor($color);

        
$offset = ($count 1) * $histogramHeight;

        foreach (
$values as $index => $value) {
            
$draw->line($index$offset$index$offset - ($value $scale));
        }
        
$count++;
    }

    
$histogram->drawImage($draw);
    
    
header"Content-Type: image/png" );
    echo 
$histogram;
}

?>

Zoek een PHP-functie

Vertaling niet beschikbaar

De PHP-handleiding is nog niet in het Nederlands vertaald, dus het scherm is in het Engels. Als u wilt, kunt u het ook in het Frans of in het Duits raadplegen.

Als je de moed voelt, kun je je vertaling aanbieden ;-)

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 30/01/2003 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/php-rf-imagick.getimagehistogram.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : http://php.net

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut