«

PHP gd库写入文字居中

时间:2024-4-30 11:01     作者:杨佳乐     分类: PHP


function mergeText_mobile($target, $data, $text)
{
    $font = IA_ROOT . "/web/resource/fonts/msyhbd.ttf";
    $colors = hex2rgb($data["color"]);

    $color = imagecolorallocate($target, $colors["red"], $colors["green"], $colors["blue"]);

    $res=imagettfbbox(16,0,$font,$text);
    logging_run($res);
    $x=(640-$res[2]*2)/2;

    //计算文字占用像素

    imagettftext($target, $data["size"], 0, $x, $data["top"] + $data["size"], $color, $font, $text);
    return $target;
}