I'm trying to find the most common color in an image giving my application the ability to search by color. I was searching php.net for something that would tell be the rgb values for each pixel of the image which i found as imagecolorat(). A little ways down someone wrote a function that finds the most common color and then converts it into hexidecimal. but there is three lines of code that I do not understand.
here is all the code
function average($img) {
$w = imagesx($img);
$h = imagesy($img);
$r = $g = $b = 0;
for($y = 0; $y < $h; $y++) {
for($x = 0; $x < $w; $x++) {
$rgb = imagecolorat($img, $x, $y);
$r += $rgb >> 16;
$g += $rgb >> 8 & 255;
$b += $rgb & 255;
}
}
$pxls = $w * $h;
$r = dechex(round($r / $pxls));
$g = dechex(round($g / $pxls));
$b = dechex(round($b / $pxls));
if(strlen($r) < 2) {
$r = 0 . $r;
}
if(strlen($g) < 2) {
$g = 0 . $g;
}
if(strlen($b) < 2) {
$b = 0 . $b;
}
return "#" . $r . $g . $b;
}
what I do not understand is this section what does the >> mean and where they use this &
$r += $rgb >> 16;
$g += $rgb >> 8 & 255;
$b += $rgb & 255;