【发布时间】:2016-05-26 02:42:51
【问题描述】:
我注意到,当使用“imagettfbbox”时,它似乎远非准确。 例如:
<?php
$text = 'hello there';
$box = imagettfbbox(12,0,'arial.ttf',$text);
$width = abs($box[0]-$box[2]);
$text = str_replace(' ',' ',$text);
echo '<svg width="500" height="200">
<g transform="scale(5)">
<text x="0" y="20" style="font-family:arial; font-size:12pt;">'.$text.'</text>
<rect x="0" y="10" width="'.$width.'" height="20" style="fill-opacity:0.5; fill:yellow;" />
</g>
</svg>';
exit;
?>
正如您在此处看到的,方框几乎完全切断了“e”。 是否有任何其他解决方案来获得准确的框宽度?
【问题讨论】:
-
我想你在这里打错了,
imagettfbbox(12,0,'arial.ttf',$text);不应该是imagettfbbox(12.0,'arial.ttf',$text);吗? PHP 使用.作为小数点。 -
@timclutton 不,完全不同的问题。
-
@andrea,不,0 是一个角度,而不是一个浮点数。
-
为什么需要它在 php 中? js能做到吗?