imageftbbox 


gd apg

CALCULATES and returns the bounding box in pixels for a TrueType2 text.





This function is an extended variant of imagettfbbox function which additionally supports the $options.

One of possible ARRAY index for $options is $linespacing that is a FLOAT value wich defines the drawing linespacing.


Check your version of GD, as versions prior to 2.0.18 may produce an error when making a $font_filename call.

The version of GD in use can be viewed by running the gd_info function.



<?php

array|false imageftbbox float $size 
                                        
float $angle
                                      
string $font_filenme
                                      
string $string
                                       array 
$options = [] )

where,

$size The font size in points

$angle 
The angle in degrees to measure the text

$font_filename 
The path to the TrueType font you wish to use

$string The text STRING to be measured

$options 
The extended variant of 
                            imagettfbbox which additionally support

?>
 

  $size   


The font size in points.



  $angle   


The angle in degrees to be written in the image.



  $font_filename   


The path to the TrueType font you wish to use.



  $string   


The text string encoded in UTF-8.



  $options   


This parameter adds extended support for the imagettfbbox function.



  1 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

if(
PHP_MAJOR_VERSION 8)
{
$var getcwd();

$font_name "$var/ttf/VeraMoIt.ttf";
// complete path
}
else
{
$font_name "ttf/VeraMoIt.ttf";


$font_size 30;
$angle_txt 0;
$pos_x 30;
$pos_y 280;
$txt 'no & zerof';

$d_base_img 'png/PNG 093 01.png';

$d_dest_img 'png/PNG 093 01 imageftbbox.png';

echo 
$d_base_img?><br><br>
<img src="<?php echo $d_base_img?>"
 alt="<?php echo $d_base_img?>
 title="<?php echo $d_base_img?>"><br><br><br> 
 
<?php

$id_dimgfile 
imagecreatefrompng($d_base_img);

$txt_color 
imagecolorallocate($id_dimgfile0xff0x000x00);

$ttf_arr 
imagettftext($id_dimgfile$font_size$angle_txt
$pos_x$pos_y$txt_color$font_name$txt );

$tffdbox_arr 
imageftbbox($font_size$angle_txt$font_name$txt);

imagepng($id_dimgfile$d_dest_img);

imagedestroy($id_dimgfile);

echo 
$d_dest_img?><br><br>
<img src="<?php echo $d_dest_img?>"
 alt="<?php echo $d_dest_img?>
 title="<?php echo $d_dest_img?>">
 
 <?php
 
echo '<pre>';
 
print_r($tffdbox_arr);
 echo 
'</pre>';
 
 echo 
'<pre>';
 
print_r($ttf_arr);
 echo 
'</pre>';
 
?> 

 RESULT   

PNG 093 01.png

PNG 093 01.png apr


PNG 093 01 imageftbbox.png

PNG 093 01 imageftbbox.png apr

THE BOUNDING BOX OF TEXT
keyCOORDINATEMEANING
00x-coordinate LOWER LEFT
10y-coordinate LOWER LEFT
2145x-coordinate LOWER RIGHT
30y-coordinate LOWER RIGHT
4145x-coordinate TOP LEFT
5-21y-coordinate TOP LEFT
60x-coordinate TOP RIGHT
7-21y-coordinate TOP RIGHT
ed48

THE VERTICES OF
THE VIRTUAL RECTANGLE OF TEXT
keyCOORDINATEMEANING
030x-coordinate LOWER LEFT
1280y-coordinate LOWER LEFT
2175x-coordinate LOWER RIGHT
3280y-coordinate LOWER RIGHT
4175x-coordinate TOP LEFT
5259y-coordinate TOP LEFT
630x-coordinate TOP RIGHT
7259y-coordinate TOP RIGHT
ed48