imageftbbox
(PHP 4 >= 4.0.7, PHP 5, PHP 7)
imageftbbox - 通过freetype2使用字体给出文本的边界框
描述
array imageftbbox ( float $size , float $angle , string $fontfile , string $text [, array $extrainfo ] )
此函数计算并返回FreeType文本的像素边界框。
参数
size
字体大小。根据您的GD版本,应该将其指定为像素大小(GD1)或点大小(GD2)。
angle
将以度数text
测量的角度。
fontfile
TrueType字体文件的名称(可以是URL)。根据PHP使用的GD库的版本,它可能会尝试通过将“.ttf”附加到文件名并沿着库定义的字体路径搜索来搜索不以“/”开头的文件。
text
要测量的字符串。
extrainfo
键 | 类型 | 含义 |
---|---|---|
行间距 | 浮动 | 定义图形线条间距 |
返回值
imageftbbox()返回一个包含8个元素的数组,代表四个点,使得文本的边界框变为:
0 | 左下角,X位置 |
---|---|
1 | 左下角,Y位置 |
2 | 右下角,X位置 |
3 | 右下角,Y位置 |
4 | 右上角,X位置 |
5 | 右上角,Y位置 |
6 | 左上角,X位置 |
7 | 左上角,Y位置 |
这些点与文本无关angle
,因此“左上角”表示在左上角水平看文本。
例子
Example #1 imageftbbox() example
<?php
//?Create?a?300x150?image
$im?=?imagecreatetruecolor(300,?150);
$black?=?imagecolorallocate($im,?0,?0,?0);
$white?=?imagecolorallocate($im,?255,?255,?255);
//?Set?the?background?to?be?white
imagefilledrectangle($im,?0,?0,?299,?299,?$white);
//?Path?to?our?font?file
$font?=?'./arial.ttf';
//?First?we?create?our?bounding?box
$bbox?=?imageftbbox(10,?0,?$font,?'The?PHP?Documentation?Group');
//?This?is?our?cordinates?for?X?and?Y
$x?=?$bbox[0]?+?(imagesx($im)?/?2)?-?($bbox[4]?/?2)?-?5;
$y?=?$bbox[1]?+?(imagesy($im)?/?2)?-?($bbox[5]?/?2)?-?5;
imagefttext($im,?10,?0,?$x,?$y,?$black,?$font,?'The?PHP?Documentation?Group');
//?Output?to?browser
header('Content-Type:?image/png');
imagepng($im);
imagedestroy($im);
?>
注释
注意:只有PHP编译时支持freetype(-- with-freetype-dir = DIR)才能使用该函数。
← imagefontwidth
imagefttext →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com