我可以每张图片使用两次以上的imagettftext吗?
问题描述:
我GOOGLE了这么多,找不到答案,PHP GD图书馆中的imagettftext()有一些限制吗?我在同一幅图像上三次调用了它,但第三次似乎没有出现。如何在同一图像上“绘制”三个imagettftext()?我可以每张图片使用两次以上的imagettftext吗?
在此先感谢!
下面的代码: 我用这个功能来生成边界:
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);
}
然后,我设置的HTML表单变量:
$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);
变量:
$image = imagecreatefrompng('images/'.$base.'.png');
$size = '12';
$angle = '0';
$font = 'font/' . strip_tags($_GET['font']) . '.ttf';
if (!$_GET['font']) $font = 'font/visitor2.ttf';
然后我用这个函数画出文字:
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);
答
功能没有限制,您可以在任何图像上尽可能多地使用它。也许你只是试图在图像之外写入错误的坐标,或者文本的颜色与背景相同,所以你看不到它。
无论如何,我建议你打印到一个文件中,当它不起作用时,函数使用的变量是否全部正确。
个人经验,我看到它在同一张照片上使用了3次以上,没有任何问题。你能分享你使用的代码吗?也许第三个电话会出错,或者你是如何做到的 – 2012-02-04 12:31:23
我添加了代码,似乎我可以使用imagettftext,但我不能使用我从互联网上复制三次的功能。 – 2012-02-04 12:48:06