php imagettftext字母间距 [英] php imagettftext letter spacing

查看:295
本文介绍了php imagettftext字母间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能绘制带有指定字母间距的ttf字符串(imagettftext)吗?

Does anybody have a function that draws a ttf string (imagettftext) with specified letter spacing?

我找不到任何内置的GD函数,因此我认为应该逐字母地添加一定的宽度来完成它.

I cannot find any build-in GD function so I think that it should be done letter by letter adding some constant width.

也许有人已经具有这样的功能:)

Maybe someone have such function already :)

ps.最好的字体是arial.ttf

ps. the best font will be arial.ttf

推荐答案

function imagettftextSp($image, $size, $angle, $x, $y, $color, $font, $text, $spacing = 0)
{        
    if ($spacing == 0)
    {
        imagettftext($image, $size, $angle, $x, $y, $color, $font, $text);
    }
    else
    {
        $temp_x = $x;
        for ($i = 0; $i < strlen($text); $i++)
        {
            $bbox = imagettftext($image, $size, $angle, $temp_x, $y, $color, $font, $text[$i]);
            $temp_x += $spacing + ($bbox[2] - $bbox[0]);
        }
    }
}

和通话:

imagettftextSp($image, 30, 0, 30, 30, $black, 'arial.ttf', $text, 23);

功能参数顺序符合标准的imagettftext参数顺序,最后一个参数是可选的$ spacing参数.如果未设置或传递的值为0,则不设置字距/字母间距.

Function parameters order meets standard imagettftext parameters order, and the last parameter is optional $spacing parameter. If not set or the passed value is 0, the kerning / letter spacing is not set.

这篇关于php imagettftext字母间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆