i want to find the dominant color in image, how can i do it ?
it would be great if i can get this in HEX code (exm: #eeeeee)
To find the most "dominant" color in an image, meaning the color that is most prevalent in the image: you'd need to create a histogram of the image.
Here is an the code from this article on how to create a histogram in PHP. (Website has gone off line several times)
> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
// get the Value from the RGB value
$V = round(($r + $g + $b) / 3);
// add the point to the histogram
$histo[$V] += $V / $n;
}
}
// find the maximum in the histogram in order to display a normated graph
$max = 0;
for ($i=0; $i<255; $i++)
{
if ($histo[$i] > $max)
{
$max = $histo[$i];
}
}
echo "";
for ($i=0; $i<255; $i++)
{
$val += $histo[$i];
$h = ( $histo[$i]/$max )*$maxheight;
echo "
";
}
echo "";
?>
In that example $max is your most "dominant" color.