如何在 Imagick PHP 中设置字体?
我似乎无法让 Imagick::setFont 在 php 中工作。直接从 手册页 获取示例:
/* 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”之类的名称。
I can't seem to get Imagick::setFont to work in php. Taking the example straight from the 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;
I get...
http://i53.tinypic.com/2d2bn9x.png
... which is clearly not comic sans. I've tried numerous fonts. It never changes. It does complain if the file doesn't exist. It does not accept names like "Arial".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用 setFont 方法时,您需要确保传递字体的绝对路径:
同样适用于您的本地主机开发,只需更改绝对路径即可。
(这是一个有点老的问题,但我还是想回答一下。)
When you're using setFont method you need to make sure you pass absolute path of the font:
Same would apply for your localhost development just change the absolute path.
(This is a bit old question but I figured to answer it anyways.)
我在这里遇到了同样的情况,我发现了这篇文章
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
I'm having the same situation here and I found this post
http://www.imagemagick.org/discourse-server/viewtopic.php?f=10&t=11937
They say Freetype library should be installed, but haven't tried yet.
UPDATE
Finally I had chance to try it and It worked.
I use
ImageMagick 6.7.6
Imagick 3.0
Freetype 2.4.9
Freetype-devel 2.3.11
Fontconfig-devel 2.8
PHP 5.3.13