函数名:imagefttext()
适用版本:PHP 4 >= 4.0.7, PHP 5, PHP 7
用法:imagefttext() 函数在图像上使用 TrueType 字体绘制文本。它返回一个布尔值,表示文本是否成功绘制到图像上。
语法:bool imagefttext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text [, array $extrainfo] )
参数:
返回值:如果成功绘制文本,则返回 true,否则返回 false。
示例:
// 创建一个新的图像资源
$image = imagecreatetruecolor(400, 200);
// 分配文本颜色
$color = imagecolorallocate($image, 255, 255, 255);
// 指定字体文件路径
$fontfile = 'arial.ttf';
// 绘制文本到图像上
imagefttext($image, 20, 0, 50, 100, $color, $fontfile, 'Hello World');
// 输出图像到浏览器
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
以上示例创建一个大小为 400x200 像素的图像,使用 Arial 字体绘制了一个大小为 20 像素的 "Hello World" 文本,起始位置为 (50, 100) 坐标。最后将图像以 PNG 格式输出到浏览器,并销毁图像资源。