plutomed Posted June 13, 2010 Share Posted June 13, 2010 imagecolourallocate is just returning black all the time. If I call this image via this link: page.php?page=captcha&backColour=0xFF|0xFF|0xFF&textColour=0x00|0x00|0x00 I get just black for all values. If I set the values manually in the code it works perfectly fine. I'm a bit confused. /****************************\ | Captcha | \****************************/ if($_GET['page'] == "captcha") { $chars = "ABCDEFGHJKLMNPQRTUVWXYZabcdefghjklmnpqrtuvwxyz2346789"; $chars = preg_split('//', $chars); $string = ""; $backColour = explode("|",$_GET['backColour']); $textColour = explode("|",$_GET['textColour']); srand(time()); for($i=0; $i<6; $i++) { $string .= $chars[rand(0, 52)]; } $im = imagecreate(75,25); //Background colour //imagecolorallocate($im, 0xFF,0xFF,0xFF); imagecolorallocate($im, $backColour[0],$backColour[1],$backColour[2]); //Border imageline($im, 0,0,74,0,imagecolorallocate($im, $textColour[0],$textColour[1],$textColour[2])); imageline($im, 0,0,0,24,imagecolorallocate($im, $textColour[0],$textColour[1],$textColour[2])); imageline($im, 74,0,74,24,imagecolorallocate($im, $textColour[0],$textColour[1],$textColour[2])); imageline($im, 0,24,74,24,imagecolorallocate($im, $textColour[0],$textColour[1],$textColour[2])); imagestring($im, 5, 5, 5, $string, imagecolorallocate($im, $textColour[0],$textColour[1],$textColour[2])); imagepng($im); $_SESSION['captcha'] = $string; imagedestroy($im); } Link to comment https://forums.phpfreaks.com/topic/204638-imagecolourallocate/ Share on other sites More sharing options...
plutomed Posted June 13, 2010 Author Share Posted June 13, 2010 Ok, instead of keeping the values as hex I have converted them to decimal. It now works. Still dunno why it didn't work with hex though. :/ Does anyone have any clue? Link to comment https://forums.phpfreaks.com/topic/204638-imagecolourallocate/#findComment-1071417 Share on other sites More sharing options...
Daniel0 Posted June 13, 2010 Share Posted June 13, 2010 Ok, instead of keeping the values as hex I have converted them to decimal. It now works. Still dunno why it didn't work with hex though. :/ Does anyone have any clue? The way that PHP converts strings to integers is by reading all characters until the first non-digit character is found. This means that (int)"0xFF" becomes 0 and not 255. See: http://dk.php.net/manual/en/language.types.string.php#language.types.string.conversion Link to comment https://forums.phpfreaks.com/topic/204638-imagecolourallocate/#findComment-1071422 Share on other sites More sharing options...
plutomed Posted June 13, 2010 Author Share Posted June 13, 2010 Ahh ok that makes sense. I thought it might have something to do with something like that. If that made sense. Thanx anyway. Link to comment https://forums.phpfreaks.com/topic/204638-imagecolourallocate/#findComment-1071425 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.