shocker-z Posted May 10, 2006 Share Posted May 10, 2006 What i'm doing is trying to implament a way to use ImageColorAllocate with hex colors, i've tryed a few ways and none of them work my image doesn't render...here is my current function which outputs the correct rgb colors if called with hexrgb('ffffff'); it will return 255, 255, 255 so thought it would work but when i use ImageColorAllocate($img_handle, hexrgb('ffffff')); my image doesn't render..[code]<?phpfunction hexrgb ($hexstr){ $int = hexdec($hexstr); $hex=array("red" => 0xFF & ($int >> 0x10), "green" => 0xFF & ($int >> 0x8), "blue" => 0xFF & $int); foreach ($hex as $i) { if ($ii) { $color=$color.', '.$i; } else { $color=$i; $ii=1; } } echo($color);}$hex=hexrgb('ffffff');?>[/code]i have also tryed with echo and return[code]<?phpfunction hexrgb ($hexstr){ $int = hexdec($hexstr); $hex=array("red" => 0xFF & ($int >> 0x10), "green" => 0xFF & ($int >> 0x8), "blue" => 0xFF & $int); foreach ($hex as $i) { if ($ii) { $color=$color.', '.$i; } else { $color=$i; $ii=1; } } echo("ImageColorAllocate(".'$img_handle'.", $color)");}hexrgb('000000');?>[/code]When i use the last function i get a blank image nothing else..Any help or diffrent functions/ways to do the same job would be great! The reason i need this is so then when pulling data froma dabase i will also be able to let a user choose the BG and text colours :)RegardsLiam Link to comment https://forums.phpfreaks.com/topic/9470-function-to-output-function/ Share on other sites More sharing options...
kenrbnsn Posted May 10, 2006 Share Posted May 10, 2006 The ImageColorAllocate() function expects that the last 3 arguments are integers, you are trying to use a string.Modify your routine to return an array containing the values for red, green, and blue:[code]<?phpfunction hexrgb ($hexstr){ $int = hexdec($hexstr); $hex=array(0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int); return ($hex);}?>[/code]To use:[code]<?phplist ($red, $green, $blue) = hexrgb('ffffff');ImageColorAllocate($img_handle, $red, $green, $blue);?>[/code]Or you can put the ImageColorAllocate() function in your function and return the value returned by ImageColorAllocate().[code]<?phpunction hexrgb ($hexstr,$img_handle){ $int = hexdec($hexstr); list($r, $g, $b) = array(0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int); return (ImageColorAllocate($img_handle, $r, $g, $b));}?>[/code]To use:[code]<? $im = hexrgb('ffeeaa',$img_handle); ?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/9470-function-to-output-function/#findComment-34951 Share on other sites More sharing options...
shocker-z Posted May 10, 2006 Author Share Posted May 10, 2006 Thats great mate thanx alot :D Link to comment https://forums.phpfreaks.com/topic/9470-function-to-output-function/#findComment-34973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.