<?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
?>
<?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_dimgfile, 0xff, 0x00, 0x00);
$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>';
?>
THE BOUNDING BOX OF TEXT | ||
key | COORDINATE | MEANING |
0 | 0 | x-coordinate LOWER LEFT |
1 | 0 | y-coordinate LOWER LEFT |
2 | 145 | x-coordinate LOWER RIGHT |
3 | 0 | y-coordinate LOWER RIGHT |
4 | 145 | x-coordinate TOP LEFT |
5 | -21 | y-coordinate TOP LEFT |
6 | 0 | x-coordinate TOP RIGHT |
7 | -21 | y-coordinate TOP RIGHT |
ed48 |
THE VERTICES OF THE VIRTUAL RECTANGLE OF TEXT | ||
key | COORDINATE | MEANING |
0 | 30 | x-coordinate LOWER LEFT |
1 | 280 | y-coordinate LOWER LEFT |
2 | 175 | x-coordinate LOWER RIGHT |
3 | 280 | y-coordinate LOWER RIGHT |
4 | 175 | x-coordinate TOP LEFT |
5 | 259 | y-coordinate TOP LEFT |
6 | 30 | x-coordinate TOP RIGHT |
7 | 259 | y-coordinate TOP RIGHT |
ed48 |