GraphicsMagick PHP扩展无法在SVG中呈现Google字体

时间:2015-09-14 09:31:10

标签: php graphicsmagick gmagick

我的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代码

for(Row row : rs) {
    utc=callback.doWith(row);
    log.info("{}", utc);
    log.info("记录的时间为:{}",
            Instant.ofEpochMilli(utc.getExpireTime()));
    if (timestamp > utc.getExpireTime()) {
        // repository.delete(n);
    }
}

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

这是SVG:

$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();

1 个答案:

答案 0 :(得分: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"
    />