function CenterText($im, $x, $y, $w, $h, $size, $text, $font, $ascent = null, $align) { global $textPadding; $ret = null; if (!$size) { $size = GetFontSize($w, $h, $text); } if ($size) { $box = imagettfbbox($size, 0, $font, $text); if (!isset($ascent)) { $ascent = abs($box[7]); } $ret = array(); $out_w = abs($box[4] - $box[0]); $out_h = abs($box[5] - $box[1]); if ($align == 'left') { $ret['x'] = $x + $textPadding; } elseif ($align == 'right') { $ret['x'] = floor($x + ($w - $out_w - $textPadding)); } else { $ret['x'] = floor($x + ($w - $out_w) / 2); } $ret['y'] = floor($y + ($h - $out_h) / 2) + $ascent; } return $ret; }
function CenterText($im, $x, $y, $w, $h, $size, $text, $font, $ascent = null) { $ret = null; if (!$size) { $size = GetFontSize($w, $h, $text); } if ($size) { $box = imagettfbbox($size, 0, $font, $text); if (!isset($ascent)) { $ascent = abs($box[7]); } $ret = array(); $out_w = abs($box[4] - $box[0]); $out_h = abs($box[5] - $box[1]); $ret['x'] = floor($x + ($w - $out_w) / 2); $ret['y'] = floor($y + ($h - $out_h) / 2) + $ascent; } return $ret; }