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);
...