Jump to content

need help allocating string to a specific color


zchikmhagnet

Recommended Posts

a php beginner/noob right here.. I need to allocate a string to a particular color..

here is the code

	for ($x = 0; $x < $width; $x++) {
	for ($y = 0; $y < $height; $y++) {

	    // get the color at this pixel in the resampled image
		$colorIndex = ImageColorAt($img, $x, $height - 1 - $y);
            $r = ($colorIndex >> 16);
            $g = ($colorIndex >>  & 255;
            $b = $colorIndex & 255;


            $color = ImageColorsForIndex($img, $colorIndex);

            // change back to indexed color mode (since that's all the PDF generator knows)
		$pdf->setColor($color['red'] / 255, $color['green'] / 255, $color['blue'] / 255);

          // symbol per color
         switch ($color) {
    case ($r = 000 and $g = 000 and $b = 000) :
        $assignedsymbol = "00";
        break;
    case ($r = 255 and $g = 255 and $b = 255) :
        $assignedsymbol = "89";
        break;
    case ($r = 255 and $g = 000 and $b = 000) :
        $assignedsymbol = "02";
        break;
    case ($r = 000 and $g = 255 and $b = 000) :
        $assignedsymbol = "03";
        break;
    case ($r = 000 and $g = 000 and $b = 255) :
        $assignedsymbol = "04";
        break;
    default:
        $assignedsymbol == "0";

}
          // generate the TEXT "grid" box
                 $pdf->addtext($baseX + ($box_hz_size * $x),
								$baseY + ($box_vt_size * $y),
								9, $assignedsymbol);

	}

}

 

please help me..  I have doubts on my switch case.. and I cant get a value to be stored..

 

 

thanks!!

You switch statement is not correct.

 

you have

 

switch($color)

{

}

 

which is fine but

 

each case has to be a test for a value of $color as that is what you are switching on. A case statement is not an if statement of other variables, so you will need your rgb values in one variable that can be checked.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.