PHP - Get the dominant color of any image

Hi E's, I tried to find a script that get the dominant color of image, and I found the below code. Lots of websites show that code, so I guess, was good:
    $i = imagecreatefromjpeg("imagem.jpg");
    for ($x=0;$x<imagesx($i);$x++) {
    for ($y=0;$y<imagesy($i);$y++) {
    $rgb = imagecolorat($i,$x,$y);
    $r = ($rgb >> 16) & 0xFF;
    $g = ($rgb >> & 0xFF;
    $b = $rgb & 0xFF;
    $rTotal += $r;
    $gTotal += $g;
    $bTotal += $b;
    $rAverage = round($rTotal/$total);
    $gAverage = round($gTotal/$total);
    $bAverage = round($bTotal/$total);

echo "$rAverage";

Open in new window

The problem is this error:
Parse error: syntax error, unexpected '&' in /home/pedro/public_html/biblioteca/tutoriais/1267/processa.php on line 8

Open in new window

Line 8 is this one:
$g = ($rgb >> & 0xFF;

Open in new window

Can you please tell me how do I put this script to work?

The best regards, JC
Pedro ChagasWebmasterAsked:
Who is Participating?
Dan CraciunConnect With a Mentor IT ConsultantCommented:
You did not copy the whole line. It used to say:
$g = ($rgb >> 8) & 0xFF;

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.