Page 1 of 1

Text over image, showing only Black

Posted: Fri Aug 15, 2008 9:00 pm
by kriptokool
I'm trying to write some WHITE text over an image I created, I'm not sure what I'm doing wrong, I've got the text and where I want it, but it alwats shows in Black color.
I've tried

Code: Select all

 
$black = ImageColorAllocate($im, 255, 255, 255); 
$black = ImageColorAllocate($im, 255, 0, 255);
$black = ImageColorAllocate($im, 0, 0, 0);
 
and it is always showing BLACK, so if somene can tell me my mistake I would really appreciate it.

Code: Select all

 
<?php 
 
 
header("Content-Type: image/jpeg"); 
 
 
$im = ImageCreateFromGif("trophybanner.gif"); 
 
 $black = ImageColorAllocate($im, 255, 255, 255); 
 
 
$start_x = 110; 
$start_y = 35; 
 
Imagettftext($im, 15, 0, $start_x, $start_y, $white, 'verdana.ttf', "Kriptokool"); 
 
 
Imagejpeg($im, '', 100); 
 
ImageDestroy($im); 
 
?> 
 
This should show the text Kriptokool in colors, but it is always Black regardless of what I use in ImageColorAllocate

Thanks

Re: Text over image, showing only Black

Posted: Sat Aug 16, 2008 4:49 am
by onion2k
You're using $white in your call to imagettftext, but you haven't allocated it. That's why it's black.

You might also be running out of colors in the palette of your image too (because you're creating an 8 bit image). That would depend on the gif you're opening though.

Re: Text over image, showing only Black

Posted: Sat Aug 16, 2008 2:03 pm
by kriptokool
yeah I notices that later on, but didn't make any changes. The only way I was able to make it work was using ImageCreateFromPNG instead of ImageCreateFromGIF.

Thanks