PHP | imagettftext() 函数

imagettftext() 函数是 PHP 中的一个内置函数,用于使用 TrueType 字体将文本写入图像。

句法:

数组imagettftext(资源$image,float $size,float $angle,
          int $x,int $y,int $color,string $fontfile,string $text)

参数:此函数接受上述八个参数,如下所述:

  • $image:它指定要处理的图像。
  • $size:它指定要使用的字体大小,以磅为单位。
  • $angle:它以度为单位指定角度。
  • $x:指定 x 坐标。
  • $y:它指定 y 坐标。
  • $color:它指定文本所需颜色的索引。
  • $fontfile:它指定要使用的字体。
  • $text:它指定要写入的文本。

返回值:此函数在成功时返回一个数组。

下面的示例说明了PHP 中的imagettftext() 函数

示例 1:

<?php
  
// Create an empty image
$im = imagecreatetruecolor(800, 250);
  
// Add text using a font from local file
$dataArr = imagettftext($im, 0, 0, 10, 10,
        imagecolorallocate($im, 0, 150, 0),
        './Pacifico.ttf', 'GeeksforGeeks');
  
// Output to browser
print("<pre>" . print_r($dataArr, true) . "</pre>");
?>

输出:

大批
(
    [0] => 8
    [1] => 12
    [2] => 18
    [3] => 12
    [4] => 18
    [5] => 7
    [6] => 8
    [7] => 7
)

示例 2:

<?php
  
// Create an empty image
$im = imagecreatetruecolor(800, 250);
  
// Add text using a font from local file
imagettftext($im, 90, 0, 100, 100, 
            imagecolorallocate($im, 0, 0, 255), 
            './RugeBoogie-Regular.ttf', 'GeeksforGeeks');
  
// Output to browser
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>

输出:

参考: https ://www.php.net/manual/en/function.imagettftext.php

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值