zchikmhagnet Posted February 25, 2010 Share Posted February 25, 2010 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!! Link to comment https://forums.phpfreaks.com/topic/193327-need-help-allocating-string-to-a-specific-color/ Share on other sites More sharing options...
jl5501 Posted February 25, 2010 Share Posted February 25, 2010 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. Link to comment https://forums.phpfreaks.com/topic/193327-need-help-allocating-string-to-a-specific-color/#findComment-1017934 Share on other sites More sharing options...
zchikmhagnet Posted February 25, 2010 Author Share Posted February 25, 2010 Thanks.. I'll keep that in mind.. I forgot to mention that it does recognize only the color white (255 255 255)so in an image that a character would represent a particular color everything is interpreted as white.. Link to comment https://forums.phpfreaks.com/topic/193327-need-help-allocating-string-to-a-specific-color/#findComment-1017946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.