imagemagick - 使用 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 text
和annotate
. 最后保存的图像只是原始图像的副本。
解决方案
您离工作解决方案只有一个逗号:
更改"+0,+100 'Testing'"
为"+0+100 'Testing'"
。
推荐阅读
- django - Django ORM原始删除查询不删除记录
- angular - angular material 7 cdkoverlay 设置透明/自定义背景类
- javascript - 单击文本属性未按预期工作
- c# - 无法在 SignalR ASP.NET Core Web API 的“已连接”状态下设置连接
- r - 如何通过仅从数据框中选择某些行来创建多个箱线图
- c++ - 修复 glDrawArrays() 的访问冲突?
- json - 验证有效 json 时 ajv 不返回
- extjs - ExtJS 6.7 Modern - 防止字段/ inputAttrTpl的自动完成
- python - Python execfile不打印,不打印变量中的值
- python - Python - 二维数组寻址填满整个数组