Imagick::queryFontMetrics 似乎没有工作。当我使用 queryFontMetrics 提供的指标来调整图像大小时,一些字体仍然被截断。有任何想法吗?
这是我的代码:
if (!file_exists($cache['dirname'].'/'.$cache['basename'])) {
try {
$draw = new ImagickDraw();
$draw->setFont($font_path['dirname'].'/'.$font_path['basename']);
$draw->setFontSize($size);
$draw->setGravity(Imagick::GRAVITY_CENTER);
$draw->setFillColor($color);
$canvas = new Imagick();
$metrics = $canvas->queryFontMetrics($draw, $text);
$canvas->newImage($metrics['textWidth'], $metrics['textHeight'], "transparent", "png");
$canvas->annotateImage($draw, 0, 0, 0, $text);
$canvas->setImageFormat('PNG');
mkdir($cache['dirname'], 0777, true);
$canvas->writeImage($cache['dirname'].'/'.$cache['basename']);
header("Content-Type: image/png");
echo $canvas;
$canvas->clear();
$canvas->destroy();
$draw->clear();
$draw->destroy();
} catch(Exception $e) {
// Output an error message
echo 'Error: ', $e->getMessage(), "";
}
} else {
// Output the image
$canvas = new Imagick($cache['dirname'].'/'.$cache['basename']);
header("Content-Type: image/png");
echo $canvas;
}