用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
# GD 库绘画改变字体 1. 使用 `imagettftext()` 绘制自定义字体,包括字体角度和字体大小以及字体文件自定义。 2. 自定义保存图像到本地。 ``` // 创建画布 $image = imagecreatetruecolor(500, 300); // 创建颜色 $white = imagecolorallocate($image, 255, 255, 255); $rand_color = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); // 绘制随机颜色 // 绘制一个矩形并使用颜色填充 imagefilledrectangle($image, 0, 0, 500, 300, $white); // 绘画 imagettftext($image, 20, 0, 100, 100, $rand_color, 'fonts/PingFang.ttc', 'Hello World'); // 自定义字体绘制 imagettftext($image,24,mt_rand(0,180),200,200,$rand_color,'fonts/PingFang.ttc','Hi My PHP'); // 自定义字体与角度绘制 // 输出到浏览器 header('content-type:image/png'); imagepng($image); // 保存图像到本地 imagepng($image,'images/gd_system_font.png'); // 销毁画布 imagedestroy($image); ```