How do I set a font in Imagick PHP?
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".
When you're using setFont method you need to make sure you pass absolute path of the font:
$im->setFont("/var/www/html/mysite/media/fonts/myCustomFont.ttf");
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.)
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
精彩评论