imagettfbbox calculates wrong rectangle when text begins with number
<p>The issue is, that when using <code>imagettfbbox</code> to calculate text dimensions, too small rectangle is returned when input text begins with numbers. This is my code:</p>

<pre><code>$fontSize = 150;
$font = "font/courier_new.ttf";
$text = $_GET["text"];

//Determine font dimensions
$bbox = imagettfbbox($fontSize, 0, $font, $text);   
$bbox["width"]=  abs($bbox[4]-$bbox[0]);
$bbox["height"]= abs($bbox[5]-$bbox[1]);

$im = imagecreatetruecolor($bbox["width"], $bbox["height"]);

echo "&lt;b&gt;Image size:&lt;/b&gt;\n";
print_r($bbox);

// This part makes transparent background
imagesavealpha($im, true);
$bg = imagecolorallocatealpha($im, 254, 254, 254,127); 
$text_color= imagecolorallocate($im, 0, 0, 0);
imagealphablending($im, false);
imagefilledrectangle($im, 0, 0, imagesx($im), imagesy($im), $bg );
imagealphablending($im, true); 


header("X-Img-Size: ".$bbox["width"]."x".$bbox["height"]."");

imagettftext($im, $fontSize, 0, 0, $bbox["height"], $text_color, $font, $text);

// This is output    
header("Content-Type: text/html");  
ob_start();
imagepng($im);
$image_data = ob_get_contents();
ob_end_clean();
imagedestroy($im);

echo "&lt;img src=\"data:image/png;base64,".base64_encode($image_data)."\" /&gt;";
</code></pre>

<p><a href="http://u8.8u.cz/testing/ttf/img.php" rel="noreferrer"><strong>Online test here</strong></a></p>

<p>These are results I get for different input text:</p>

<p><img src="https://i.stack.imgur.com/b78gQ.png" alt="image description"></p>

<p><img src="https://i.stack.imgur.com/vOXxk.png" alt="image description"></p>

<p><img src="https://i.stack.imgur.com/0mIK0.png" alt="image description"></p>

<p>How can I fix that?</p>