$srcImg = imagecreatefrompng($BackgroundImage);
$NewpriceColor = imagecolorallocate($srcImg, 231, 71, 57);//设置颜色为红色
$Newprice = 10.00;
$fontBox = imagettfbbox(55, 0, $Galyon, $Newprice);//获取文字所需的尺寸大小
// 居中算法
// ceil((700 - $fontBox[2]) / 2) 宽度
// ceil(($height - $fontBox[1] - $fontBox[7]) / 2) 高度
imagettftext($srcImg, 55, 0, ceil((700 - $fontBox[2]) / 2), 395, $NewpriceColor, $Galyon, $Newprice . "元");
imagesavealpha($srcImg,true);
// imagepng($srcImg,__RUN__ . 'thumb.png');
header("Content-type:image/png");//png格式
imagepng($srcImg);//输出
PHP imagettftext 文字居中
最新推荐文章于 2023-09-26 22:38:06 发布