这里需要填写本地的字体路径,而且WIN系统必须是自带的字体才行。我使用的是:simhei.ttf
下载地址是:simhei.ttf
//1.配置图片路径
$src = "imgshuiyin/1.png";
//2.获取图片信息
$info = getimagesize($src);
//3.通过编号获取图像类型
$type = image_type_to_extension($info[2],false);
//4.在内存中创建和图像类型一样的图像
$fun = "imagecreatefrom".$type;
//5.图片复制到内存
$image = $fun($src);
/*操作图片*/
//1.设置字体的路径
$font = "imgshuiyin/font/simhei.ttf";
//2.填写水印内容
$content = "huhu905";
//3.设置字体颜色和透明度
$color = imagecolorallocatealpha($image, 155, 155, 255, 0);
//4.写入文字 (图片资源,字体大小,旋转角度,坐标x,坐标y,颜色,字体文件,内容)
$a = imagettftext($image, 50, 0, 400, 100, $color, $font, $content);
//var_dump($a);exit;
/*输出图片*/
//浏览器输出
header("Content-type:".$info['mime']);
$fun = "image".$type;
$fun($image);
//保存图片
$fun($image,'imgshuiyin/bg_res.'.$type);
/*销毁图片*/
imagedestroy($image);
exit;
https://blog.youkuaiyun.com/inite/article/details/80289423