, imagettfbbox, , , , , .
function imagettftext_cr(&$im, $size, $angle, $x, $y, $color, $fontfile, $text)
{
$bbox = imagettfbbox($size, $angle, $fontfile, $text);
$dx = ($bbox[2]-$bbox[0])/2.0 - ($bbox[2]-$bbox[4])/2.0;
$dy = ($bbox[3]-$bbox[1])/2.0 + ($bbox[7]-$bbox[1])/2.0;
$px = $x-$dx;
$py = $y-$dy;
return imagettftext($im, $size, $angle, $px, $py, $color, $fontfile, $text);
}
: PHP...
. , , $angle . $width - .
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;
}