函数名:imagettftext()
适用版本:PHP 4 >= 4.0.7, PHP 5, PHP 7
用法:imagettftext() 函数用于将 TrueType 字体的文本添加到图像上。
语法:bool imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
参数:
- $image:图像资源,通过 imagecreatetruecolor() 或者其他图像创建函数创建的图像。
- $size:文本的大小,以像素为单位。
- $angle:文本的旋转角度,以度为单位(逆时针方向为正)。
- $x:文本的起始 x 坐标。
- $y:文本的起始 y 坐标。
- $color:文本的颜色,可以使用 imagecolorallocate() 函数来创建。
- $fontfile:TrueType 字体文件的路径。
- $text:要添加的文本。
返回值:成功时返回 true,失败时返回 false。
示例:
以上示例创建了一个空白图像,设置了背景颜色和文本颜色,然后使用 imagettftext() 函数将文本 "Hello World!" 添加到图像上,并输出为 PNG 图片。请确保将 $fontFile 替换为真实的 TrueType 字体文件路径。