ImageTTFText() issue

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
artoonie
Forum Newbie
Posts: 10
Joined: Sat Jun 09, 2007 3:06 am

ImageTTFText() issue

Post by artoonie »

Code: Select all

imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text)
The color of the text to be written does not show up correctly on all images. How would I fix this?

Example:
On the following images, everything has been correctly implemented. I can show the code if necessary, but I doubt the whole thing is necessary.
Not working: http://www.priceypixel.com/pics/custom/ ... 50&angle=0
The color is supposed to be black ("&c1=0&c2=0&c3=0", where c1, c2, and c3 are R, G, and B respectively)

Working: http://www.priceypixel.com/pics/custom/ ... 00&angle=0
(The color shows up as black)



How would I fix this? I've been searching everywhere, but haven't found any answers (a few people with the same problem though)



Thanks,
Artoonie[/syntax]
artoonie
Forum Newbie
Posts: 10
Joined: Sat Jun 09, 2007 3:06 am

Post by artoonie »

Maybe if somehow I created a transparent box over the image and wrote the text on that, would it work?[/syntax]
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

It's one of two possible problems I think. Either you're not assigning the color to the image correctly using imagecolorallocate() prior to writing the text, or you've run out of palette space in the GIF image. GIFs can only have 256 colors in them* so if there's already 256 colors you won't be able to assign another color, and it'll be a bit random with what the text is drawn as.

* Technically GIFs can have as many colors as you want using a multi frame wide palette technique, but thats a: really complicated, and b: not really possible with PHP.
artoonie
Forum Newbie
Posts: 10
Joined: Sat Jun 09, 2007 3:06 am

Post by artoonie »

It was the latter.


...and i got it working, thank you so much!


Solution: use bool imagetruecolortopalette ( resource $image, bool $dither, int $ncolors ) and set the maximum number of colors (int $ncolors) to 255, which would allow room for 1 more color if the chosen color is not in the current pallet.




Thanks a zillion times two, this was a big help.
Post Reply