imagettfbbox with glyphs having a negative left bearing

Hello,

Glyphs having negative left bearing (like the lower case ‘j’ in Times.ttf) are truncated on the left side.

[php]<?php
$img = imagecreatetruecolor(200, 200);
$white = imagecolorallocate($img,255,255,255);
imagefilledrectangle($img, 0, 0, 400, 400, $white);
$green = imagecolorallocate($img, 0, 255, 0);
$red = imagecolorallocate($img, 255,0, 0);
$black = imagecolorallocate($img, 0,0, 0);
$string = ‘j’; //“”;
$fonte = ‘assets/fontes/Times.ttf’;

$a = imagettfbbox( 30, 0, $fonte, $string );
$aa = 'imagettfbbox : ’ . print_r( $a, true );
imagettftext($img, 10, 0, 50, 20, $black, $fonte, $aa );

imagettftext($img, 60, 0, 0, 60, $green, $fonte, $string ); // left truncated
imagettftext($img, 60, 0, 20, 100, $red, $fonte, $string ); // OK with a left value
header(“Content-type: image/png”);
//imagesavealpha($img, true);
imagepng($img);
imagedestroy($img);
?>[/php]

The first green ‘j’ is truncated, the red one is correctly displayed due to the left value of the fourth parameter to the imagettftext.

This parameter should be equal to the value of the left bearing for the glyph : how to get this value ?

Thanks for any help.

Sponsor our Newsletter | Privacy Policy | Terms of Service