Jump to content

[SOLVED] Problem with ImageColorAllocate


lxndr

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.