Solved

PHP - Get the dominant color of any image

Posted on 2014-04-03
1
1,590 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 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