php 开启 imageftbbox,PHP imageftbbox()用法及代码示例

imageftbbox()函数是PHP中的内置函数,用于通过freetype2使用字体来计算文本的边界框。

用法:

array imageftbbox( float $size, array $angle,

string $fontfile, string $text, array $extrainfo )

参数:该函数接受上述和以下所述的五个参数:

$size:它以磅为单位指定字体大小。

$angle:它指定以度为单位的角度,在该角度下将测量文本。

$fontfile:它指定字体文件名。

$text:它指定要测量的字符串。

$extrainfo (Optional):它指定了额外的信息。

返回值:该函数成功返回一个数组。

下面给出的程序说明了PHP中的imageftbbox()函数:

程序1:

// Create bounding box with local font file

$bbox = imageftbbox(100, 100, './Pacifico.ttf', 'GeeksforGeeks');

// Print the boundbox data

print("

".print_r($bbox, true)."
");

?>

输出:

Array

(

[0] => 47

[1] => -13

[2] => -91

[3] => -806

[4] => -264

[5] => -776

[6] => -124

[7] => 17

)

程序2:

// Create an image

$im = imagecreatetruecolor(800, 250);

// Set the background to be light blue

imagefilledrectangle($im, 0, 0, 299, 299,

imagecolorallocate($im, 0, 0, 100));

// Create bounding box with local font file

$bbox = imageftbbox(10, 0, './Pacifico.ttf',

'GeeksforGeeks');

// Calculate coordinates using bounding box

$x = $bbox[0] + 130;

$y = $bbox[1] + 130;

// Add text

imagefttext($im, 50, 0, $x, $y, imagecolorallocate($im,

0, 150, 0), './Pacifico.ttf', 'GeeksforGeeks');

// Output to browser

header('Content-Type:image/png');

imagepng($im);

imagedestroy($im);

?>

输出:

21aff228a9ab0c1d74252df385cfeaac.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值