2016-12-25 48 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查找结束坐标