JBS103 Posted February 19, 2007 Share Posted February 19, 2007 I've created a function to allocate colors with Hexadecimal codes. Right now, it isn't creating any errors, its only outputting black. <?php header ("Content-type: image/png"); function getColor($colorValue, &$img_handle) { $colorValue = trim($colorValue, "#"); $colorValue = str_split($colorValue, 2); for($x = 0; $x < 3; $x++) { $colorValue[$x] = "0x".$colorValue[$x]; } return ImageColorAllocate($img_handle, $colorValue[0], $colorValue[1], $colorValue[2]); } $img_handle = ImageCreate (20, 20); $color = getColor("#FFFFFF", $img_handle); imagefill($img_handle, 0, 0, $color); ImagePng ($img_handle); ?> Is there a better way to do this all together? The function seems to output correctly. Link to comment https://forums.phpfreaks.com/topic/39214-solved-imagecolorallocate/ Share on other sites More sharing options...
JBS103 Posted February 19, 2007 Author Share Posted February 19, 2007 Nevermind. I settled for this if anyone is interested. <?php header ("Content-type: image/png"); function getColor($colorValue, &$img_handle) { $colorValue = trim($colorValue, "#"); $colorValue = str_split($colorValue, 2); return ImageColorAllocate($img_handle, hexdec($colorValue[0]), hexdec($colorValue[1]), hexdec($colorValue[2])); } $img_handle = ImageCreate (20, 20); $color = getColor("#FFFFFF", $img_handle); imagefill($img_handle, 0, 0, $color); ImagePng ($img_handle); ?> Link to comment https://forums.phpfreaks.com/topic/39214-solved-imagecolorallocate/#findComment-188982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.