hi everyone at php builder!
i'm new to php and I've posted this thread at other forums but gotten no replies,
I basically need to find the most prominent color in any image jpg or gif, i'm running through the pixels collecting an array and getting the mean... i don't know that much about php or image processing and I don't know if I'm on the right track, or if it's possible at all... any help is greatly appreciated.
this is my code so far:
<?php
// open an image
$im2 = imagecreatefromjpeg('example.jpg');
// make truecolor to web safe
$im = imagetruecolortopalette($im2, false, 255);
$imsiz = getimagesize('example.jpg');
$imx = $imsiz[0];
$imy = $imsiz[1];
$totalPixels = $imy+$imx;
print($totalPixels.'JJJJ');
for($y = 0; $y < $imy ;$y++)
{
for($x = 0; $x <$imx; $x++)
{
$color_index = imagecolorat($im, $x, $y);
$color_tran = imagecolorsforindex($im, $color_index);
for($i=0; $i < $totalPixels; $i++){
$imR[$totalPixels] = array($color_tran[red]);
$imG[$totalPixels] = array($color_tran[green]);
$imB[$totalPixels] = array($color_tran[blue]);
}
}
}
$imRTotal = count($imR);
$imGTotal = count($imG);
$imBTotal = count($imB);
$imRMean = array_sum($imR)/$imRTotal;
$imGMean = array_sum($imG)/$imGTotal;
$imBMean = array_sum($imB)/$imBTotal;
?>