imagick:無法查詢字體度量 (Imagick: Failed to query the font metrics)


問題描述

imagick:無法查詢字體度量 (Imagick: Failed to query the font metrics)

I'm working on (what should be) a simple script that will add text to an image.  After going over my script several times looking for any mistakes I finally decided to try running a sample from php.net and I encountered the same, nondescript,  error: "Failed to query the font metrics". Here's the code:

/* Text to write */
$text = "Hello World!";

/* Create Imagick objects */
$image = new Imagick();
$draw = new ImagickDraw();
$color = new ImagickPixel('#000000');
$background = new ImagickPixel('none'); // Transparent

/* Font properties */
$draw->setFont('Arial');
$draw->setFontSize(50);
$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('/tmp/file.png', $image);

I can not for the life of me find any information via google about this error. Nor can I find adequate documentation on this method or potential causes of failure. Basically, I'm stumped. If anyone could provide insight or a fix it would be greatly appreciated.

ImageMagic version: ImageMagick 6.6.5-10 2011-04-06 Q16

Imagick module version: 3.1.0b1 


參考解法

方法 1:

have you tried cli version ? is imagemagick installed on server ? if yes then run a command like 

system('convert -background lightblue -fill blue \
      -font Candice -pointsize 72 label:Anthony \
      label.gif  ');

see if you have imagenamed label.gif in server after running script. for your reference http://www.imagemagick.org/Usage/text/

方法 2:

For those having similar issues, the PHP Imagick exceptions aren't always the most descriptive. I could have saved myself a lot of time examining the output from the Image Magic application installed on the server first. Just something to keep in mind. To view a list of the currently installed delegates(modules) use the command convert -list configure and examine the line that starts with "DELEGATES" from the output. If you encounter the same error, I recommend checking here first. I found I was missing the freetype and ghostscript delegates. After installing the dependancies and a quick recompile of ImageMagick everything works like a charm.

(by PizanoHardikPizano)

參考文件

  1. Imagick: Failed to query the font metrics (CC BY-SA 3.0/4.0)

#imagick #imagemagick #PHP






相關問題

Imagick 安裝錯誤 - 類未定義 (Imagick Installation Errors - Class Undefined)

GD/Imagick 不保存我的圖像 (GD/Imagick doesn't save my image)

Imagick 使用不同的目錄和數據庫 PDF 來縮略圖 JPG (Imagick using different directory and database PDF to thumbnail JPG)

如何在不損失分辨率和質量的情況下減小圖像尺寸(高度、寬度) (How to decrease image size(height, width) without losing its resolution and quality)

Đang cố gắng để tưởng tượng chạy trên PHP 5.4.3 ở Windows x64 (Trying to get imagick running on PHP 5.4.3 at Windows x64)

WampServer 和 Imagemagick,無法識別 imagick php 模塊 (WampServer and Imagemagick, imagick php module not recogized)

PHP Imagick:如何將自定義圖像屬性保存到文件 (PHP Imagick: How to save custom image property to file)

PHP Imagick - 顯示多圖像 TIFF 的第一片 (PHP Imagick - display first slice of mutli image TIFF)

可以加快 php/imagick 中的圖像加載速度 (Possible to speed up image loading in php/imagick)

PHP imagick 相當於 -define png:color-type=6 (PHP imagick equivalent of -define png:color-type=6)

php Imagick::levelImage 使用 (php Imagick::levelImage usage)

imagick:無法查詢字體度量 (Imagick: Failed to query the font metrics)







留言討論