【发布时间】:2015-07-11 09:06:08
【问题描述】:
对不起我的英语! 我在图像上使用 imagick php 和覆盖文本时遇到了这个问题。 调整图像宽度时,字体变小。 这是两个图像宽度的示例,第一个是 350px,第二个是 1728px: http://i.stack.imgur.com/8kRo0.jpg http://i.stack.imgur.com/TedDO.jpg
$f->userFontSize 是登录用户选择在其图像上显示的字体大小。
if(trim($_GET['full']) != 'si'){
$width = 350;
$height = 350;
} else {
$width = getWidth($root . $f->imagePathFull);
$height = getHeight($root . $f->imagePathFull);
}
$image = new imagick();
$draw = new imagickDraw();
$pixel = new imagickPixel('white');
$image->newImage($width, $height, $pixel);
$image->readImage($root . $f->imagePathNormal);
$image->resizeImage ( $width, $height, imagick::FILTER_LANCZOS, 1, TRUE);
$fontPath = $root . '/assets/fonts/Mermaid.ttf';
$draw->setFillColor('black');
$draw->setFont($fontPath);
$draw->setFontSize(12 + $f->userFontSize);
$draw->setGravity(1);
$draw->setTextAntialias(true);
$draw->setFillOpacity(".55");
$image->annotateImage($draw, 5,0, 0, "text text text");
$image->setImageFormat("jpg");
header( "Content-Type: image/jpeg" );
echo $image->getImageBlob();
$image->clear();
当我打印分辨率为 1728 像素的图像时,文本非常小。如何根据图像大小增加字体大小? 谢谢! :)
【问题讨论】:
-
如果您知道字体大小 12 适合您的 350 像素宽度,那么可能会进行一些试验和错误,对于此示例,假设字体大小 20 适合您的 1728 像素宽度。我们有可能的字体大小为 12、13、14、15、16、17、18、19 和 20。在这种情况下,您的最大宽度和最小宽度之间的差异是 1378 像素,让我们将其除以可能的字体大小(即9),因此对于 153px 的每一步,您大致希望将字体大小增加一。逻辑应该成立,但请调整确切的变量以适合您的项目。 :)