Page 1 of 1
ImageTTFText() issue
Posted: Sat Jun 09, 2007 3:14 am
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]
Posted: Sat Jun 09, 2007 11:47 pm
by artoonie
Maybe if somehow I created a transparent box over the image and wrote the text on that, would it work?[/syntax]
Posted: Sun Jun 10, 2007 5:55 am
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.
Posted: Sun Jun 10, 2007 6:32 pm
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.