need help allocating string to a specific color

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zchikmhagnet
Forum Newbie
Posts: 2
Joined: Thu Feb 25, 2010 5:17 am

need help allocating string to a specific color

Post by zchikmhagnet »

Hello! a PHP newbie right here..

I need to allocate a string to a particular color..

I have a code but it only outputs a string assigned to white(255 255 255)

Code: Select all

    for ($x = 0; $x < $width; $x++) {
        for ($y = 0; $y < $height; $y++) {
 
        
            $colorIndex = ImageColorAt($img, $x, $height - 1 - $y);
            $color = ImageColorsForIndex($img, $colorIndex);
            $color['red']=intval((($color['red'])+15)/32)*32;    
            $color['green']=intval((($color['green'])+15)/32)*32;
            $color['blue']=intval((($color['blue'])+15)/32)*32;
           
            // symbol per color
         switch ($color) {
    case ($color['red'] = 255 and $color['green'] = 255 and $color['blue'] = 255) :
        $assignedsymbol = "00";
        break;
    case ($color['red'] = 148 and $color['green'] = 91 and $color['blue'] = 128) :
        $assignedsymbol = "01";
        break;
    case ($color['red'] = 206 and $color['green'] = 148 and $color['blue'] = 186) :
        $assignedsymbol = "02";
        break;
    case ($color['red'] = 000 and $color['green'] = 255 and $color['blue'] = 000) :
        $assignedsymbol = "03";
        break;
 
 
............
 default:
        $assignedsymbol == "0";
}
 
 
any other ideas or alternatives? they are greatly appreciated.. thanks!!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: need help allocating string to a specific color

Post by AbraCadaver »

This is not how a switch statement works. You are switching on the value of color, which I assume is a number or string, yet all of your case expressions evaluate to a boolean true. You must likely need to use IF statements instead, or redesign your switch correctly.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
zchikmhagnet
Forum Newbie
Posts: 2
Joined: Thu Feb 25, 2010 5:17 am

Re: need help allocating string to a specific color

Post by zchikmhagnet »

thanks!! I've done IF statements and it went out well..

Code: Select all

  if ($color['red'] == 255 && $color['green'] == 255 && $color['blue'] == 255) {
            $assignedsymbol = "00";
            } elseif ($color['red'] == 148 && $color['green'] == 91 && $color['blue'] == 128) {
            $assignedsymbol = "01";
            } elseif ($color['red'] == 206 && $color['green'] == 148 && $color['blue'] == 186) {
            $assignedsymbol = "02";
            }




thanks again
Post Reply