lxndr Posted June 9, 2008 Share Posted June 9, 2008 I have some code which is intended to write text into an existing png image using one of 8 different colours. I noticed that it works as intended about a dozen times and then the text is always black each subsequent time. I wrote some debug to capture what was going on and have to admit to being totally confused. This is the code which assigns the rgb colours and then calls ImageColorAllocate: $red = hexdec( substr( $hexval, 0, 2 ) ); $green = hexdec( substr( $hexval, 2, 2 ) ); $blue = hexdec( substr( $hexval, 4, 2 ) ); $color = ImageColorAllocate( $myimage, $red, $green, $blue ); Then later this is the code that writes the text into the image: imagettftext( $myimage, $fontsize, $textangle, $start_x, $start_y, $color, $fontfile, $string ); What I don't understand are the values being returned from the ImageColorAllocate call on subsequent calls, why is the value for color continuing to rise even though I'm only using 8 actual different colours? I'm also fairly sure it didn't used to behave this way but my server has recently been upgraded from php4 to php5 so wondering if that has anything to do with it. Anyway, if anyone who has a much better understanding of ImageColorAllocate can tell me where I'm going wrong or better still what I need to do to fix the problem I'd be very grateful. Here are the values for hexval and color that are returned by subsequent program executions: 01. hexval: #C0C0C0, $color: 18 02. hexval: #FF0033, $color: 33 03. hexval: #FFFFFF, $color: 71 04. hexval: #FFFF00, $color: 95 05. hexval: #FF0033, $color: 111 06. hexval: #00FF00, $color: 127 07. hexval: #6666FF, $color: 135 08. hexval: #00C0C0, $color: 148 09. hexval: #FF0033, $color: 168 10. hexval: #FFFFFF, $color: 173 11. hexval: #FFC0C0, $color: 176 12. hexval: #00C0C0, $color: 184 13. hexval: #00C0C0, $color: 213 14. hexval: #00FFFF, $color: 216 15. hexval: #00FF00, $color: - TIA for any help. Ian __ Link to comment https://forums.phpfreaks.com/topic/109364-solved-problem-with-imagecolorallocate/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.