Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:imageftbbox_Php_Image_Gd - Fatal编程技术网

PHP:imageftbbox

PHP:imageftbbox,php,image,gd,Php,Image,Gd,PHP imageftbbox中文本边界框的应用是什么 在的示例中,它用于确定imagefttext函数的坐标。有必要吗?也许我错过了什么 ... // 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)

PHP imageftbbox中文本边界框的应用是什么

在的示例中,它用于确定imagefttext函数的坐标。有必要吗?也许我错过了什么

...

// 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');

...

这对函数imageftbboximagettfbbox允许您知道文本在图像上的空间大小(第一个用于自由类型文本,第二个用于真实类型文本)

这样,如果您有一个生成一些图像并在其上写入可变文本(用户输入或类似的内容)的应用程序,您可以使用诸如imagefttext或ImageTTFTText(相同的区别-字体)之类的函数来决定如何/在何处放置该文本

因此,您可以执行以下操作:

$bbox = imagettfbbox(34, 0, 'myriadb.otf', strtoupper($name)); //font size 34, text in a horizontal line, use myriadb.otf as font, the user name as variable text
$text_width = $bbox[2]; // this is how much space the name will take
$margin = (CARD_WIDTH-($text_width))/2; // a constant knowing the width of the resulting card.. this way we will center the name..
imagettftext($image, 34, 0, $margin, $y, $white, 'myriadb.otf', strtoupper($name));// $image resource, 34-same size, same angle, the margin is the the x coordinate, fixed $y, color, font and the same text
他有关于他的广泛信息

以下是链接信息中的一些相关信息:

(图片版权归Flylib所有)

从上图中,您可以看到有4个点和8个信息(如文档所述):

同样,如文档所述,无论角度如何,此信息都是相对于文本的。因此,如果将文本顺时针旋转90度,则边界框将变为:

Array information     Bounding box coordinate
===================================================================
    0                 X coordinate of the upper left hand corner
    1                 Y coordinate of the upper left hand corner
    2                 X coordinate of the lower left hand corner
    3                 Y coordinate of the lower left hand corner
    4                 X coordinate of the lower right hand corner
    5                 Y coordinate of the lower right hand corner
    6                 X coordinate of the upper right hand corner
    7                 Y coordinate of the upper right hand corner
我相信另一个资源将帮助您更好地掌握包围盒的基本概念:


我添加了GD标记,因为此函数(以及相关函数)是GD库的一部分。。只是为了让想要学习使用gd的用户更容易找到。注意:在本例中,我使用了ttf函数,而不是ft函数(如您的示例中的函数),但行为类似于调用未定义的函数CARD_WIDTH()。如何使用此函数?这是一个常量..您也可以在该行的注释中看到。。它是要渲染的图片总宽度的值
Array information     Bounding box coordinate
===================================================================
    0                 X coordinate of the upper left hand corner
    1                 Y coordinate of the upper left hand corner
    2                 X coordinate of the lower left hand corner
    3                 Y coordinate of the lower left hand corner
    4                 X coordinate of the lower right hand corner
    5                 Y coordinate of the lower right hand corner
    6                 X coordinate of the upper right hand corner
    7                 Y coordinate of the upper right hand corner