【问题标题】:How do I set a font in Imagick PHP?如何在 Imagick PHP 中设置字体?
【发布时间】:2015-08-25 17:52:49
【问题描述】:

我似乎无法让 Imagick::setFont 在 php 中工作。直接以man page为例:

/* Create new imagick object */
$im = new Imagick();

/* Set the font for the object */
$im->setFont("comic.ttf");

/* Create new caption */
$im->newPseudoImage(100, 100, "caption:Hello");

$im->setformat('png');
header('Content-type: image/png');
echo $im;

我明白了……

http://i53.tinypic.com/2d2bn9x.png

...这显然不是漫画。我试过很多字体。它永远不会改变。如果文件不存在,它会抱怨。它不接受像“Arial”这样的名称。

【问题讨论】:

  • 字体文件和脚本在同一个文件夹吗?如果不是,则必须正确设置路径...
  • @evolve,字体肯定在正确的位置。如果我移动它,脚本就会失败。如果它在正确的位置,它会呈现但字体不会改变。

标签: php fonts imagick


【解决方案1】:

我在这里也遇到同样的情况,我找到了这篇文章

http://www.imagemagick.org/discourse-server/viewtopic.php?f=10&t=11937

他们说应该安装 Freetype 库,但还没有尝试。

更新

最后我有机会尝试它并且它成功了。

我用

ImageMagick 6.7.6

Imagick 3.0

Freetype 2.4.9

Freetype-devel 2.3.11

Fontconfig-devel 2.8

PHP 5.3.13

【讨论】:

    【解决方案2】:

    当您使用 setFont 方法时,您需要确保传递字体的绝对路径:

    $im->setFont("/var/www/html/mysite/media/fonts/myCustomFont.ttf");
    

    同样适用于您的 localhost 开发,只需更改绝对路径即可。

    (这是一个有点老的问题,但我还是想回答一下。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      • 2015-04-11
      • 2022-01-24
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      • 2012-12-11
      相关资源
      最近更新 更多