2

我正在尝试通过 imagettftext 放置多色文本。
我试着一个字母一个字母地画,但间距太可怕了。
这是我的代码:

$usrname_split = str_split("MarioErmando");
$onecharwidth  = imagefontwidth((int)$font)*(12/8);
foreach($usrname_split as $key=>$letter){
    if($key == 0){
        // first letter
        imagettftext($im, 12, 0, $xusrname, 15, $blue, $font, $letter);
        $oldletters = "$letter";
    }else{
        $posarr=imageftbbox(12, 0 ,$font, $oldletters);
        $posx = $posarr["2"];
        imagefttext($im, 12, 0, $posx, 15, $red, $font, $letter);
        $oldletters .= "$letter";
    }
}

输出: 输出
请注意,文本是动态的。
是否可以通过 imagettftext 实现多色文本而没有可怕的间距?

问候,马里奥厄曼多。

4

1 回答 1

0

为了测试,用这个替换你的代码:

 $string="Mario Ermando";
 $last_string= substr( $string, 1 );

        imagettftext($im, 12, 0, $xusrname, 20, $blue, $font, $string[0]);  //first letter "M"
        imagefttext($im, 12, 0, 12, 20, $red, $font, $last_string);

在此处输入图像描述

我认为问题是当你分开写每封信时

于 2014-05-02T16:18:18.867 回答