Solved

PHP - Get the dominant color of any image

Posted on 2014-04-03
1
1,561 Views
Last Modified: 2014-04-04
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;
    $total++;
    }
    }
     
    $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
0
Comment
Question by:Pedro Chagas
1 Comment
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39977130
You did not copy the whole line. It used to say:
$g = ($rgb >> 8) & 0xFF;

Open in new window

HTH,
Dan
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How has this flight information been added to this website? 7 31
Split wordpress loop 35 56
mysql query for sum() 3 28
Ajax and PHP 9 29
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question