我的Ubuntu14.04笔记本安装了GraphicsMagick和PHP扩展(GMagick)。当我从命令行运行以下命令时,
gm convert /usr/share/fonts/truetype/google-fonts/RockSalt.ttf -font 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 memories will last forever</text> </g> </g> </g></svg>发布于 2015-12-11 12:02:23
您需要编辑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"
/>https://stackoverflow.com/questions/32561432
复制相似问题