Code: Select all
<?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;
?>