I googled this a lot and couldn’t find an answer, is there some kind of limitation to imagettftext() in PHP GD Library? I called it three times on the same image but the third doesn’t seem to appear. How can I “draw” three imagettftext() on the same image?
Thanks in advance!
Here’s the code:
I use this function to generate a border:
function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px){
for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++){
for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++){
$bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);
}
}
return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);
}
Then I set the variables from the HTML form:
$text = strip_tags(htmlspecialchars_decode(stripslashes($_GET['text'])));
$text = str_replace('>', '>', $text);
$text = str_replace('<', '<', $text);
$text = str_replace('"', '"', $text);
$text = str_replace('and_sign', '&', $text);
$text2 = strip_tags(htmlspecialchars_decode(stripslashes($_GET['text2'])));
$text2 = str_replace('>', '>', $text2);
$text2 = str_replace('<', '<', $text2);
$text2 = str_replace('"', '"', $text2);
$text2 = str_replace('and_sign', '&', $text2);
$text3 = strip_tags(htmlspecialchars_decode(stripslashes($_GET['text3'])));
$text3 = str_replace('>', '>', $text3);
$text3 = str_replace('<', '<', $text3);
$text3 = str_replace('"', '"', $text3);
$text3 = str_replace('and_sign', '&', $text3);
More variables:
$image = imagecreatefrompng('images/'.$base.'.png');
$size = '12';
$angle = '0';
$font = 'font/' . strip_tags($_GET['font']) . '.ttf';
if (!$_GET['font']) $font = 'font/visitor2.ttf';
And then I use the function to draw the text:
imagettfstroketext($image, $size, $angle, 4, 12, $text_colour, $text_outline, $font, $text, 1);
imagettfstroketext($image, $size, $angle, 10, 20, $text_colour, $text_outline, $font, $text2, 1);
imagettfstroketext($image, $size, $angle, 4, 30, $text_colour, $text_outline, $font, $text3, 1);
There is no limitation on the function, you can use it as much as you want on any image. Maybe you are just trying to write outside of the image with bad coordinates or the color of the text is the same as the background so you can’t see it.
Anyway, I advise you to print to a file the variables used by the function when it doesn’t work to see if all is right.