public function createImg($result, $string){
$backgroundPath = '背景图路径';
$img = imagecreatefromjpeg($backgroundPath); //背景图
//设置字体颜色
$black = imagecolorallocate($img, 0, 0, 0);
//字体大小
$size = 20;
if(strlen($string) > 24){
$size = 18;
}
//字体
$font = "assets/fonts/msyhbd.ttf";
//将ttf文字写到图片中
imagettftext($img, $size, 0, 108, 502, $black, $font, $string);
$filePathDir = '生成路径';
if (!is_dir($filePathDir)) {
mkdir($filePathDir, 0777, true);
}
$filePath = $filePathDir.time().rand(0,999).'.jpg';
imagejpeg($img,$filePath);
return $filePath;
}
php把文字写到图片生成
最新推荐文章于 2026-04-09 01:52:49 发布

2180

被折叠的 条评论
为什么被折叠?



