<?php
array|false imagettfbbox ( float $size ,
float $angle,
string $font_filename,
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 = Options for written
?>
<?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 = 16;
$angle_txt = 23;
$pos_x = 49;
$pos_y = 196;
$txt = 'Anyway ... we were found!';
$d_base_img = 'png/baseXx.png';
$d_dest_img = 'png/PNG 092 01imagettfbbox.png';
$id_dimgfile = imagecreatefrompng($d_base_img);
$pol_line = imagecolorallocate($id_dimgfile, 255, 0, 255);
imagepng($id_dimgfile, $d_base_img);
echo $d_base_img; ?><br><br>
<img src="<?php echo $d_base_img; ?>"
alt="<?php echo $d_base_img; ?> app" title="<?php echo $d_base_img; ?>"><br><br><br>
<?php
$txt_color = imagecolorallocate($id_dimgfile, 255, 0, 0);
$ttf_arr = imagettftext($id_dimgfile, $font_size, $angle_txt,
$pos_x, $pos_y, $txt_color, $font_name, $txt );
$ttfdbox_arr = imagettfbbox($font_size, $angle_txt, $font_name, $txt);
imagepolygon($id_dimgfile, $ttf_arr, 4, $pol_line);
imagepng($id_dimgfile, $d_dest_img);
echo $d_dest_img; ?><br><br>
<img src="<?php echo $d_dest_img; ?>"
alt="<?php echo $d_dest_img; ?> app" title="<?php echo $d_dest_img; ?>">
<?php
echo '<br><br>THE BOUNDING BOX OF TEXT:<pre>';
print_r($ttfdbox_arr);
echo '</pre><br>';
echo '<br>THE VERTICES OF THE VIRTUAL RECTANGLE OF TEXT:<pre>';
print_r($ttf_arr);
echo '</pre><br>';
THE BOUNDING BOX OF TEXT | ||
key | COORDINATE | MEANING |
0 | -1 | x-coordinate LOWER LEFT |
1 | 5 | y-coordinate LOWER LEFT |
2 | 298 | x-coordinate LOWER RIGHT |
3 | -121 | y-coordinate LOWER RIGHT |
4 | 290 | x-coordinate TOP LEFT |
5 | -141 | y-coordinate TOP LEFT |
6 | -9 | x-coordinate TOP RIGHT |
7 | -14 | y-coordinate TOP RIGHT |
ed48 |
THE VERTICES OF THE VIRTUAL RECTANGLE OF TEXT | ||
key | COORDINATE | MEANING |
0 | 48 | x-coordinate LOWER LEFT |
1 | 201 | y-coordinate LOWER LEFT |
2 | 347 | x-coordinate LOWER RIGHT |
3 | 75 | y-coordinate LOWER RIGHT |
4 | 339 | x-coordinate TOP LEFT |
5 | 55 | y-coordinate TOP LEFT |
6 | 40 | x-coordinate TOP RIGHT |
7 | 182 | y-coordinate TOP RIGHT |
ed48 |