本文共 1133 字,大约阅读时间需要 3 分钟。
imagefttext()函数是PHP中的一个内置函数,用于使用FreeType 2使用字体将文本写入图像。
用法:
array imagefttext( resource $image, float $size, float $angle,
int $x, int $y, int $color, string $fontfile,
string $text, array $extrainfo )
参数:该函数接受上述和以下所述的九个参数:
$image:它指定要处理的图像。
$size:它指定要使用的字体大小(以磅为单位)。
$angle:它以度为单位指定角度。
$x:它指定x坐标。
$y:它指定y坐标。
$color:它指定文本所需颜色的索引。
$fontfile:它指定要使用的字体。
$text:它指定要写入的文本。
$extrainfo (Optional):它指定了额外的信息。
返回值:该函数成功返回一个数组。
以下示例说明了PHP中的imagefttext()函数。
范例1:
// Create an empty image
$im = imagecreatetruecolor(800, 250);
// Add text using a font from local file
$dataArr = imagefttext($im, 0, 0, 10, 10,
imagecolorallocate($im, 0, 150, 0),
'./Pacifico.ttf', 'GeeksforGeeks');
// Output to browser
print("
".print_r($dataArr, true)."");
?>
输出:
Array
(
[0] => 8
[1] => 12
[2] => 18
[3] => 12
[4] => 18
[5] => 7
[6] => 8
[7] => 7
)
程序2:
// Create an empty image
$im = imagecreatetruecolor(800, 250);
// Add text using a font from local file
imagefttext($im, 50, 0, 100, 100,
imagecolorallocate($im, 0, 150, 0),
'./Pacifico.ttf', 'GeeksforGeeks');
// Output to browser
header('Content-Type:image/png');
imagepng($im);
imagedestroy($im);
?>
输出:
转载地址:https://blog.csdn.net/weixin_39861823/article/details/115502416 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!