<?php
/* show image */
echo "<img src=gc.jpg><br>";
/* create an image resource based on an existing image file. */
$img = imagecreatefromjpeg('gc.jpg');
/* get the image resource width and height. */
$imgW = imagesx($img);
$imgH = imagesy($img);
/* loop through every pixel of the image. */
for ($col = 0; $imgW > $col; $col++) {
for ($row = 0; $imgH > $row; $row++) {
/* get the index of the color of the current pixel. */
$rgb = imagecolorat($img, $col, $row);
/* extract the RGB values into the total variables. */
$rTot += (($rgb >> 16) & 0xFF);
$gTot += (($rgb >> 8) & 0xFF);
$bTot += ($rgb & 0xFF);
/* increase the total amount of pixels. */
$tot++;
}
}
/* get the rounded average RGB variables. */
$rAverage = round($rTot / $tot);
$gAverage = round($gTot / $tot);
$bAverage = round($bTot / $tot);
/* show the result */
echo "Red: $rAverage<br>Green: $gAverage<br>Blue: $bAverage";
?>
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.