2012-02-04 84 views
0

我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('&gt;', '>', $text); 
$text = str_replace('&lt;', '<', $text); 
$text = str_replace('&quot;', '"', $text); 
$text = str_replace('and_sign', '&', $text); 

$text2 = strip_tags(htmlspecialchars_decode(stripslashes($_GET['text2']))); 
$text2 = str_replace('&gt;', '>', $text2); 
$text2 = str_replace('&lt;', '<', $text2); 
$text2 = str_replace('&quot;', '"', $text2); 
$text2 = str_replace('and_sign', '&', $text2); 

$text3 = strip_tags(htmlspecialchars_decode(stripslashes($_GET['text3']))); 
$text3 = str_replace('&gt;', '>', $text3); 
$text3 = str_replace('&lt;', '<', $text3); 
$text3 = str_replace('&quot;', '"', $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); 
+0

個人經驗,我看到它在同一張照片上使用了3次以上,沒有任何問題。你能分享你使用的代碼嗎?也許第三個電話會出錯,或者你是如何做到的 – 2012-02-04 12:31:23

+0

我添加了代碼,似乎我可以使用imagettftext,但我不能使用我從互聯網上覆制三次的功能。 – 2012-02-04 12:48:06

回答

0

功能沒有限制,您可以在任何圖像上儘可能多地使用它。也許你只是試圖在圖像之外寫入錯誤的座標,或者文本的顏色與背景相同,所以你看不到它。

無論如何,我建議你打印到一個文件中,當它不起作用時,函數使用的變量是否全部正確。

相關問題