Imagick setFont not working in web but works in console
Posted: 2015-11-18T10:59:10-07:00
Here's my code:
And ImageMagick configuration file:
If I call this in console mode by:
, it's OK. But when I accessing by web interface: http://test-srv/testing/test.php, It raise an exception:
Fatal error: Uncaught exception 'ImagickException' with message 'The path does not exist: /home/nginx/testing/annabelle' in /home/nginx/testing/test.php:15 Stack trace: #0 /home/nginx/testing/test.php(15): ImagickDraw->setfont('annabelle') #1 {main} thrown in /home/nginx/testing/test.php on line 15
I tried use setFontFamily() instead of setFont() like this:
Or using the font file instead using font name in setFont() like this:
The image created but not using the font specified like this:
If I run the code in console, I get the right one like this :
Code: Select all
<?php
/* Create Imagick objects */
$image = new \Imagick();
$draw = new \ImagickDraw();
$color = new \ImagickPixel('#000000');
$background = new \ImagickPixel('none'); // Transparent
/* Font properties */
$draw->setFont("annabelle");
$draw->setFontSize(80);
$draw->setFillColor($color);
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);
/* Get font metrics */
$metrics = $image->queryFontMetrics($draw, $text);
/* Create text */
$draw->annotation(0, $metrics['ascender'], $text);
/* Create image */
$image->newImage($metrics['textWidth'], $metrics['textHeight'], background);
$image->setImageFormat('png');
$image->drawImage($draw);
/* Save image */
file_put_contents('imagick_test.png', $image);
?>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<typemap>
<include file="type-dejavu.xml" />
<include file="type-ghostscript.xml" />
<include file="type-windows.xml" />
<type name="annabelle" family="annabelle" glyphs="/home/nginx/testing/annabelle.ttf" />
</typemap>
Code: Select all
nginx@test-srv ~/testing $ php -f test.php
Fatal error: Uncaught exception 'ImagickException' with message 'The path does not exist: /home/nginx/testing/annabelle' in /home/nginx/testing/test.php:15 Stack trace: #0 /home/nginx/testing/test.php(15): ImagickDraw->setfont('annabelle') #1 {main} thrown in /home/nginx/testing/test.php on line 15
I tried use setFontFamily() instead of setFont() like this:
Code: Select all
...
/* Font properties */
$draw->setFontFamily("annabelle");
$draw->setFontSize(80);
...
Code: Select all
...
/* Font properties */
$draw->setFont("annabelle.ttf");
$draw->setFontSize(80);
...