ImageMagick和imagick_type_gen无法识别添加的字体 [英] ImageMagick and imagick_type_gen don't recognize added fonts

查看:243
本文介绍了ImageMagick和imagick_type_gen无法识别添加的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我正在运行CentOS服务器,PHP 5.4.440和ImageMagick 6.5.4,并且我尝试添加其他字体,例如以龙虾为例.到目前为止,这是我所做的:

Ok, I'm running a CentOS server, PHP 5.4.440 and ImageMagick 6.5.4 and I'm trying to add additional fonts, as an example let's say Lobster. Here's what I've done so far:

将Lobster.ttf上载到/home/myusername/fonts/

Uploaded Lobster.ttf to /home/myusername/fonts/

从SSH运行"perl imagick_type_gen> fonts.xml".这导致字体文件很大,但是没有包含对Lobster.otf或Lobster.ttf的引用

From SSH, ran "perl imagick_type_gen > fonts.xml". This resulted in a large font file, but contained NO references to either Lobster.otf or Lobster.ttf

相反,我生成了自己的type.xml并将其保存到/home/myusername/.magick/.这是标记:

Instead, I generated my own type.xml and saved it to /home/myusername/.magick/. Here's the markup:

<?xml version="1.0"?>
<typemap>
    <type format="otf" name="Lobster" fullname="Lobster" family="Lobster" glyphs="/home/myusername/fonts/Lobster.otf" />
</typemap>

通过SSH,我编辑了/user/lib64/ImageMagick-6.5.4/config/type.xml并插入了引用自定义type.xml的节点:

Via SSH, I edited /user/lib64/ImageMagick-6.5.4/config/type.xml and inserted the node that references the custom type.xml:

<typemap>
    <include file="type-ghostscript.xml" />
    <include file="/home/myusername/.magick/type.xml" />
</typemap>

重新启动服务器.

这时,我可以使用以下字体列出字体:

At this point, I can list the fonts using this:

$image = new Imagick();
$fonts = $image->queryfonts();
foreach($fonts as $font) {
    echo $font . '<br />';
}

然后龙虾出现在列表中.但是,将SVG转换为PNG并不使用Lobster字体.我在这里看到了其他问题,类似于我的问题,它们似乎起作用了.我该怎么做才能使系统识别添加的字体?

And Lobster shows up in the list. However, converting an SVG to PNG isn't using the Lobster font. I've seen other questions in here similar to mine and they seem to work. What do I need to do to get the system to recognize the added font?

这是我用来渲染以龙虾为字体的图像的代码:

Here's the code I'm using to render what should be an image using Lobster as the font:

//Setup SVG to be read by Imagick.
$SVG = '<?xml version="1.0" encoding="utf-8"?>';
$SVG .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';
$SVG .= '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="158px" height="92px" viewBox="0 0 158 92" enable-background="new 0 0 158 92" xml:space="preserve">';
$SVG .= '<text transform="matrix(1 0 0 1 32 58)" font-family="Lobster" font-style="normal" font-size="20px" font-weight="400">Lobster</text>';
$SVG .= '</svg>';

$image = new Imagick();

//Convert SVG to JPG
$image->readImageBlob($SVG);
$image->setImageFormat("jpeg");

//Save the thumbnail.
$save_path = 'lobster-test.jpg';
$image->writeImage($save_path);

echo '<img src="'.$save_path.'">';

我在这里完全不知所措.救命!

I'm at a complete loss here. Help!

推荐答案

此处讨论了完整的解决方案: http://www.multipole.org/discourse-server/viewtopic.php ?t = 25630

A full solution is discussed here: http://www.multipole.org/discourse-server/viewtopic.php?t=25630

但这是简短的版本:

  1. 为您的自定义上传字体创建目录 /usr/share/fonts/default-我创建了一个名为"custom"的目录.
  2. 将要安装的字体复制到/usr/share/fonts/default/custom
  3. 运行命令fc-cache -v/usr/share/fonts
  1. Make a directory for your custom uploaded fonts in /usr/share/fonts/default - I created a directory called "custom".
  2. Copy the fonts you want to install to /usr/share/fonts/default/custom
  3. Run the command fc-cache -v /usr/share/fonts

此后,ImageMagick将使用SVG中的字体.一个警告是,您必须使用嵌入在字体中的字体系列声明.例如,Lobster.otf实际上列出了"Lobster 1.4".

After this, ImageMagick will use the fonts in the SVG. The one Caveat is that you MUST use the font-family declaration embeded in the font. For example, Lobster.otf actually lists "Lobster 1.4".

如果您已经安装了字体并使用正确的字体系列名称,则可以呈现字体!

If you've got the font installed and use the proper font-family name, you'll get your fonts rendered!

这篇关于ImageMagick和imagick_type_gen无法识别添加的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆