php imagettftext字体位置

php imagettftext字体位置,php,text,position,imagettftext,Php,Text,Position,Imagettftext,我正在使用imagettftext()将字母写入图像。问题是我不知道图像中的字母位置 如您所见,我使用imagettfbbox()绘制了图像和字母的边框,但字母位于右侧时,字母边框也位于左侧 所以问题是:我怎么知道字母从哪里开始(在x轴上)?每个字母看起来都有不同的“偏移量”,我只想知道它是用来画黑色边框的 这是我用来创建上面链接的图像的代码: //$w,$h,$bl(baseline) and $s taken from a text in an html page $string = "

我正在使用
imagettftext()
将字母写入图像。问题是我不知道图像中的字母位置

如您所见,我使用
imagettfbbox()
绘制了图像和字母的边框,但字母位于右侧时,字母边框也位于左侧

所以问题是:我怎么知道字母从哪里开始(在x轴上)?每个字母看起来都有不同的“偏移量”,我只想知道它是用来画黑色边框的

这是我用来创建上面链接的图像的代码:

//$w,$h,$bl(baseline) and $s taken from a text in an html page

$string = "a";
$font = "font/times.ttf";
$h = 247;
$w = 94; //106 for letter "b"
$bl = 54;

header('Content-type: image/png');
$im = imagecreatetruecolor($w, $h);

$back = imagecolorallocate($im, 200, 200, 200);
$asd =  imagecolorallocate($im, 0, 255, 255);

imagefilledrectangle($im, 0, 0, $w, $h, $back);

$x = 0;
$y = $h-$bl;
$s = 212 * 0.75;

imagettftext($im,$s,0,$x,$y,$asd,$font,$string);

$prova = imagettfbbox($s, 0, 'font/times.ttf', $string);
imageline($im,$prova[0],$h - $bl + $prova[1],$prova[2],$h - $bl + $prova[3],imagecolorallocate($im, 0, 0, 0));
imageline($im,$prova[4],$h - $bl + $prova[5],$prova[2],$h - $bl + $prova[3],imagecolorallocate($im, 0, 0, 0));
imageline($im,$prova[4],$h - $bl + $prova[5],$prova[6],$h - $bl + $prova[7],imagecolorallocate($im, 0, 0, 0));
imageline($im,$prova[0],$h - $bl + $prova[1],$prova[6],$h - $bl + $prova[7],imagecolorallocate($im, 0, 0, 0));
imageline($im,$prova[0],$h - $bl + $prova[1],$prova[4],$h - $bl + $prova[5],imagecolorallocate($im, 0, 0, 0));
imageline($im,$prova[2],$h - $bl + $prova[3],$prova[6],$h - $bl + $prova[7],imagecolorallocate($im, 0, 0, 0));

imageline($im,0,0,$w,$h,imagecolorallocate($im, 0, 255, 0));
imageline($im,0,$h,$w,0,imagecolorallocate($im, 0, 255, 0));

imagepng($im);
imagedestroy($im);

我刚刚在函数的手册页中找到原因: