使用Elixir Mogrify向图像添加文本

3
我在 Elixir 中使用 Mogrify 包时遇到了问题。我想给一张图片添加文字。不知何故,这张图片可以打开并保存副本,但我无法对副本进行任何更改。
    img_url = to_string(:code.priv_dir(:jobs)) <> "/tristar.png"
    save_url = to_string(:code.priv_dir(:jobs)) <> "/tristar_copy.png"

    Mogrify.open(img_url)
    |> Mogrify.custom("pointsize", 200)
    |> Mogrify.custom("gravity", "North")
    |> Mogrify.custom("annotate", "+0,+100 'Testing'")
    |> IO.inspect(label: "\n===== Image Pre-Save =============================================")
    |> Mogrify.save(path: save_url)

在 Iex 中的输出如下:
===== Image Pre-Save =============================================:
%Mogrify.Image{
  animated: false,
  buffer: nil,
  dirty: %{},
  ext: ".png",
  format: nil,
  frame_count: 1,
  height: nil,
  operations: [
    {"pointsize", 200},
    {"gravity", "North"},
    {"annotate", "+0,+100 'Testing'"}
  ],
  path: "/code/elixir/_build/dev/lib/jobs/priv/tristar.png",
  width: nil
}
%Mogrify.Image{
  animated: false,
  buffer: nil,
  dirty: %{},
  ext: ".png",
  format: nil,
  frame_count: 1,
  height: nil,
  operations: [],
  path: "/code/elixir/_build/dev/lib/jobs/priv/tristar_copy.png",
  width: nil
}

我尝试使用“自定义”添加填充和描边。我尝试使用“标签”,“绘制文本”和“注释”。最终保存的图像仅是原始图像的副本。
2个回答

4

你离一个可行的解决方案只差一个逗号:

"+0,+100 'Testing'"改为"+0+100 'Testing'"


0
花了很多时间排查后,我找到了问题的所在。至少可以确定,我没有为ImageMagick安装字体。
我通过替换文件中的 `` 为 `` 来修复这个问题。文件路径是: `usr/local/Cellar/imagemagick/7.0.10-7/etc/ImageMagick-7/type.xml`
然后,编辑 `/usr/local/Cellar/imagemagick/7.0.10-7/etc/ImageMagick-7/type-apple.xml` 文件,在该文件中搜索并替换所有字形路径为 `/System/Library/Fonts/Supplemental`。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接