Text over image, showing only Black

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kriptokool
Forum Newbie
Posts: 2
Joined: Fri Aug 15, 2008 8:54 pm

Text over image, showing only Black

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Text over image, showing only Black

Post 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.
kriptokool
Forum Newbie
Posts: 2
Joined: Fri Aug 15, 2008 8:54 pm

Re: Text over image, showing only Black

Post 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
Post Reply