Solved

PHP - Get the dominant color of any image

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses how to create an extensible mechanism for linked drop downs.
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now