Solved

PHP - Get the dominant color of any image

Posted on 2014-04-03
1
1,542 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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 …
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 dynamically set the form action using jQuery.

770 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