Jump to content

Image Colors analize


Jet-J

Recommended Posts

count colours, pixel by pixel

 

<?php
$im = imagecreatefrompng('myfile.png');

$ccount = array();
for ($x=0, $w = imagesx($im); $x < $w; $x++)
{
    for ($y=0, $h = imagesy($im); $y < $h; $y++)
    {
        $c = imagecolorat($im, $x, $y);
        $a = imagecolorsforindex($im, $c);
        $ccount[vsprintf('%02X%02X%02X', $a)]++;
    }
}
$max = max($ccount);
$sum = array_sum($ccount);
$mostused = array_search($max, $ccount);
$pcent = $max*100/$sum;
printf ('Most used #%s : %0.2f%%', $mostused, $pcent);
?>

Link to comment
https://forums.phpfreaks.com/topic/108011-image-colors-analize/#findComment-553822
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.