2016-12-25 115 views
2

我需要使用GD庫將文本粘貼到另一個文本之後。 Example here。我試着做以下方式PHP的GD庫,如何將文本粘貼到另一個文本塊後

$text = wordwrap($text, 80, "\n"); 
$count = substr_count($text, "\n"); 
$string_number = 14; 
$pos = 0; 
if ($count >= $string_number) { 
    for ($i = 0; $i < 14; $i++) { 
     $pos = stripos($text, "\n", $pos) + 1; 
    } 
    $text = substr($text, 0, $pos); 
    //Attempt to calculate coordinates of a text block 
    $text_cord = imagettfbbox(14, 0, $font_300_path, $text); 
    //And paste text after the end coordinate 
    imagettftext($image, 14, 0, 130, $text_cord[3], $blue, font_300_path, 'Need to paste'); 
} 

imagettftext($image, 14, 0, 130, 293, $black, $font_300_path, $text); 

但如果我這樣做,這樣我得到this

所以,我的問題是,我怎麼能貼上其他文本塊之後文本?

+0

你的意思是粘貼? – HddnTHA

+0

哦,是的!固定。 – DarkyDash

+0

您的代碼不完整。請粘貼您用來創建圖像的所有代碼,以便可以複製問題。請參見[如何創建最小,完整和可驗證的示例](https://stackoverflow.com/help/mcve)。 – timclutton

回答

0

問題解決。我剛用font_size * line_height * number_of_new_lines查找結束座標