php gd - 多色图像ttftext

问题描述 投票:0回答:1

我正在尝试通过 imagettftext 放置多色文本。
我尝试逐字绘制,但字偶距很差。

这是我的代码:

$usrname_split = str_split("Text");
$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 实现具有更好字距调整的多色文本?

php gd truetype imagettftext
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);

enter image description here

我认为问题在于你单独写每个字母

© www.soinside.com 2019 - 2024. All rights reserved.