首页 > 解决方案 > 使用 Elixir Mogrify 向图像添加文本

问题描述

我在使用 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
}

我试过用custom. 我试过使用label,draw textannotate. 最后保存的图像只是原始图像的副本。

标签: imagemagickelixirmogrify

解决方案


您离工作解决方案只有一个逗号:

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


推荐阅读