且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用PHP向图像添加文本

更新时间:2023-12-04 10:00:58

您要为此使用imagettfbbox()来计算水平偏移量:

You want to use imagettfbbox() for this to calculate the horizontal offset:

$bbox = imagettfbbox(13, 0, $font_path, $text_line_1);
$xOffset = ($bbox[2] - $bbox[0]) / 2;

现在只需从所需位置减去偏移量即可.

Now just subtract the offset from your desired position and you are good to go.