PHP图⽚⽂字合成图⽚⽂字合成、
function comments($bigImgPath,$Absolute_Path,$nickName) {
$bigImgPath = '1.png';//背景图
$img = imagecreatefromstring(file_get_contents($bigImgPath));
// $font = $Absolute_Path.'simsun.ttc';//字体
$font = $Absolute_Path.'PINGFANG MEDIUM.TTF';//字体
$black = imagecolorallocate($img, 255, 255, 255);//字体颜⾊ RGB
$hz = substr(strrchr($bigImgPath, '.'), 1);
$path = $Absolute_Path.'image/';
$imgage = $path.'end'.date("YmdHis").rand(10000,99999).".".$hz;
$fontSize = 30; //字体⼤⼩
$circleSize = 0; //旋转⾓度
$left = 310; //左边距
$top = 320; //顶边距你现在看⼀下名字的颜⾊
list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
$fontBox = imagettfbbox($fontSize, 0, $font, $nickName);//⽂字⽔平居中实质
imagettftext ( $img, $fontSize, 0, ceil(($bgWidth - $fontBox[2]) / 2), $top, $black, $font, $nickName ); // imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $nickName);
switch ($bgType) {
case 1: //gif
imagegif($img,$imgage);
break;
case 2: //jpg
imagejpeg($img,$imgage);
break;
case 3: //jpg
imagepng($img,$imgage);
break;
default:
break;
}
return $imgage;
} |