PHP: imageftbbox

Каково применение ограничивающей рамки текста в 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'); ... 

Flylib имеет обширную информацию о imagettfbox () .

Вот некоторая релевантная информация из связанной информации:

введите описание изображения здесь

(изображение copyright Flylib)

Из приведенного выше изображения вы можете видеть, что есть 4 точки с 8 информацией (как уже говорилось в документации):

 Array information Bounding box coordinate =================================================================== 0 X coordinate of the lower left hand corner 1 Y coordinate of the lower left hand corner 2 X coordinate of the lower right hand corner 3 Y coordinate of the lower right hand corner 4 X coordinate of the upper right hand corner 5 Y coordinate of the upper right hand corner 6 X coordinate of the upper left hand corner 7 Y coordinate of the upper left hand corner 

Опять же, как указано в документации, эта информация относится к тексту независимо от угла. Поэтому, если вы поворачиваете текст на 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 

Другие ресурсы, которые, я считаю, помогут вам лучше понять основную идею вокруг ограничивающей рамки:

пара функций imageftbbox и imagettfbbox позволяет вам узнать, сколько места займет ваш текст на изображении (первый используется для текста свободного текста, а второй для текста с истинным типом)

таким образом, если у вас есть приложение, которое генерирует некоторые изображения и записывает на них переменный текст (ввод пользователя или что-то подобное), вы можете решить, как / где разместить этот текст, используя такие функции, как imagefttext или imagettftext (такая же разница – шрифт)

поэтому вы можете сделать что-то вроде:

 $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