2

我的 Ubuntu 14.04 笔记本电脑安装了 GraphicsMagick 和 PHP 扩展 (GMagick)。当我从命令行运行以下命令时,

gm convert -font /usr/share/fonts/truetype/google-fonts/RockSalt.ttf svg_file.svg jpeg_file.jpg

根据需要使用字体呈现 JPEG。但是,这个 PHP 代码

$gm = new Gmagick();
$draw = new GmagickDraw();
$draw->setfont("/usr/share/fonts/truetype/google-fonts/RockSalt.ttf");
$gm->readImageBlob($svg);
$gm->setImageFormat("jpeg");
$gm->drawimage($draw);
$gm->writeImage($jpgFile);
$gm->clear();

未能执行相同操作并使用默认字体创建 JPEG。这里可能是什么问题?

这是 SVG:

<?xml version="1.0"?><svg xmlns="http://www.w3.org/2000/svg"    xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="737" height="521"><defs/> <g class="main">  <title>Main</title>  <rect fill="#ffffff" stroke-width="0" x="27.24188" y="429.44421" width="682.51626" height="68.18413" id="svg_2" class="element" opacity="0.75" stroke="#000000"/>  <g text-anchor="start" font-family="Rock Salt" fill="#000" font-size="20" class="element textarea" id="svg_3">   <rect opacity="0"  stroke-width="0" x="27.24188" y="429.44421" width="682.51626" height="68.18413" id="svg_4"/>   <g class="textGroup">    <text class="eol" y="470.98331" x="44.46314" xml:space="preserve">Your&#xA0;memories&#xA0;will&#xA0;last&#xA0;forever</text>   </g>  </g> </g></svg>
4

1 回答 1

0

您需要编辑 GraphicMagick 的 type.mkg 文件,以便加载字体。 https://sourceforge.net/p/graphicsmagick/discussion/250738/thread/5c00e815/

这是所需格式的示例: https ://github.com/CliffsDover/graphicsmagick/blob/master/config/type-windows.mgk.in

<?xml version="1.0"?>
<typemap>
  <type
    name="Arial"
    fullname="Arial"
    family="Arial"
    weight="400"
    style="normal"
    stretch="normal"
    glyphs="@windows_font_dir@arial.ttf"
    />
  <type
    name="Arial-Black"
    fullname="Arial Black"
    family="Arial"
    weight="900"
    style="normal"
    stretch="normal"
    glyphs="@windows_font_dir@ariblk.ttf"
    />
  <type
    name="Arial-Bold"
    fullname="Arial Bold"
    family="Arial"
    weight="700"
    style="normal"
    stretch="normal"
    glyphs="@windows_font_dir@arialbd.ttf"
    />
于 2015-12-11T04:02:22.593 回答