[请益] 请问GD产字体图.X轴如何正确不会偏移

楼主: max701218 (Max)   2014-10-18 01:29:09
各位前辈大家好,想请教一下,我用GD的imagettfbbox()产出字转图
(图尺寸需跟字一样大)
只要宽一点的字体,文字的右边都会被裁到,是X轴没抓准还是width没抓准?
请问有其他解决的办法吗?
PS.因主机不够好,不能使用imagick处理,因为需好几秒才会产出图
为顾及速度,请问有能用GD解决的方式,或是有其他模组件可使用吗?
恳请解惑,附上程式码及裁到右边的字图
https://www.flickr.com/photos/57332716@N03/15371483427/in/photostream/player/
谢谢
<?php
//计算字的画框大小
function textBox($size ,$file ,$string){
$rect= imagettfbbox( $size, 0, $file, $string );
$minX = min(array($rect[0],$rect[2],$rect[4],$rect[6]));
$maxX = max(array($rect[0],$rect[2],$rect[4],$rect[6]));
$minY = min(array($rect[1],$rect[3],$rect[5],$rect[7]));
$maxY = max(array($rect[1],$rect[3],$rect[5],$rect[7]));
return array(
"left" => abs($minX),
"top" => abs($minY),
"width" => $maxX - $minX,
"height" => $maxY - $minY,
"box" => $rect
);
}
$size = 52;
$file = 'font/arial.ttf';
$string = "M";
$box = textBox($size ,$file ,$string);
$im= imagecreatetruecolor( $box['width'], $box['height'] );
$black = ImageColorAllocate ($im,255, 255, 255);
$fill= imagefill( $im, 0, 0, $black );
$fcolor= imagecolorallocate( $im, 0, 0, 0);
imagettftext( $im, $size, 0, 0, $box['top'], $fcolor, $file, $string );
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
作者: hit1205 (帮你把勇气装满)   2014-10-18 02:08:00
感觉跟 #1KAYkW5I 是一样的情形?
楼主: max701218 (Max)   2014-10-18 15:21:00
网址失效,请问那篇有写解决方法吗?
作者: hom1130 (.拨云见日.)   2014-10-18 16:50:00
一楼那是文章代码,#1KAYkW5I还在
楼主: max701218 (Max)   2014-10-19 21:54:00
hom1130 谢谢提醒,我不太懂操作,找到文章了hit1205 从你上一篇文章的回答找到答案,已解决 感谢

Links booklink

Contact Us: admin [ a t ] ucptt.com