【发布时间】:2011-02-17 20:54:43
【问题描述】:
我有一行文本需要在 GD 图像中换行和居中。我也在使用 ttf 字体。有什么可以给我一些帮助吗?
我已经设法得到一些文本来包装做以下事情,但现在我需要把它放在中心:
function wrap($fontSize, $angle, $fontFace, $string, $width){
$ret = "";
$arr = explode(' ', $string);
foreach ( $arr as $word ){
$teststring = $ret.' '.$word;
$testbox = imagettfbbox($fontSize, $angle, $fontFace, $teststring);
if ( $testbox[2] > $width ){
$ret.=($ret==""?"":"\n").$word;
} else {
$ret.=($ret==""?"":' ').$word;
}
}
return $ret;
}
【问题讨论】:
标签: php text image-processing formatting gd