如何在Imagick PHP中设置字体?

时间:2011-06-23 00:39:58

标签: php fonts imagick

我似乎无法让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;

我明白了......

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

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

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:2)

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

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

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

(这是一个有点老问题,但无论如何我想回答它。)