<?php
// 创建一个空白图像并填充背景
$im = imagecreatetruecolor(400, 30);
$bg = imagecolorallocate($im, 255, 255, 255); // 白色背景
imagefilledrectangle($im, 0, 0, 399, 29, $bg);
// 设置字体颜色
$text_color = imagecolorallocate($im, 0, 0, 0); // 黑色文字
// 使用imagettftext函数将文本绘制到图像上
imagettftext($im, 20, 0, 10, 20, $text_color, 'arial.ttf', 'Hello World!');
// 输出图像到浏览器
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
imagecreatetruecolor() 函数创建一个 400x30 像素的空白图像。imagecolorallocate() 分配白色作为背景颜色,并用 imagefilledrectangle() 填充整个图像区域。imagecolorallocate() 分配黑色作为文字颜色。imagettftext() 函数将指定的文本("Hello World!")以指定的字体(arial.ttf)和大小(20)绘制到图像上。参数包括图像资源、字体大小、旋转角度、起始坐标、颜色、字体文件路径和要绘制的文本。header() 设置内容类型为 image/png,然后用 imagepng() 将图像输出到浏览器,并使用 imagedestroy() 释放内存。如果你需要进一步的帮助或有其他问题,请告诉我!
上一篇:php intval函数
下一篇:php获取当天0点整的时间戳
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站