PHP生成图片时文字如何具中

// 加载字体文件
$fontFile = public_path().'/simsun.ttc';
// 获取文字尺寸
$size = 20; // 文字大小
$bbox = imagettfbbox($size, 0, $fontFile, $name); // 获取文字边框框框
// 计算居中位置
$width = $bbox[2] - $bbox[0]; // 文字宽度
$height = $bbox[1] - $bbox[7]; // 文字高度
$x = (imagesx($backImg) - $width) / 2; // 水平居中位置
$y = (imagesy($backImg) - $height) / 2 + $bbox[1]; // 垂直居中位置

$textColor = imagecolorallocate($qrcodeImg, 0, 0, 0); // 黑色文字
imagettftext($backImg, $size, 0, $x, $y, $textColor, $fontFile, $name);
//输出合成图片
imagepng($backImg, $path);
PHP生成图片时文字如何具中
$text = '中文汉字'.$imgtext.'TONY';
	$textword ='编号'.$testword;


$font = 'msyh.ttf';
/*
$image:它指定要处理的图像。
$size:它指定要使用的字体大小,以磅为单位。
$angle:它以度为单位指定角度。
$x:指定 x 坐标。
$y:它指定 y 坐标。
$color:它指定文本所需颜色的索引。
$fontfile:它指定要使用的字体。
$text:它指定要写入的文本。
*/
	//imagettftext($fframe, 40, 0, $txt_x, $txt_y, $black, $font, $textword);
imagettftext($fframe, 40, 0, $txt_x, $txt_y, $black, $font, $textword);

猜你喜欢

转载自blog.csdn.net/ffffffff8/article/details/133325370