tests courtesy of Claude
This commit is contained in:
@@ -43,22 +43,34 @@ defmodule LabelmakerWeb.LabelController do
|
||||
end
|
||||
|
||||
defp size_settings(args, %{height: "", width: ""} = options) do
|
||||
# Escape % characters in label text to prevent ImageMagick property interpolation
|
||||
escaped_label =
|
||||
options.label
|
||||
|> String.slice(0, Constants.max_label_length())
|
||||
|> String.replace("%", "%%")
|
||||
|
||||
args ++
|
||||
[
|
||||
"-pointsize",
|
||||
options.size,
|
||||
"label:#{String.slice(options.label, 0, Constants.max_label_length())}"
|
||||
"label:#{escaped_label}"
|
||||
]
|
||||
end
|
||||
|
||||
defp size_settings(args, %{align: alignment, height: height, width: width} = options) do
|
||||
# Escape % characters in label text to prevent ImageMagick property interpolation
|
||||
escaped_label =
|
||||
options.label
|
||||
|> String.slice(0, Constants.max_label_length())
|
||||
|> String.replace("%", "%%")
|
||||
|
||||
args ++
|
||||
[
|
||||
"-gravity",
|
||||
Tools.process_gravity(alignment),
|
||||
"-size",
|
||||
"#{width}x#{height}",
|
||||
"caption:#{String.slice(options.label, 0, Constants.max_label_length())}"
|
||||
"caption:#{escaped_label}"
|
||||
]
|
||||
end
|
||||
|
||||
@@ -75,11 +87,19 @@ defmodule LabelmakerWeb.LabelController do
|
||||
end
|
||||
|
||||
defp final_settings(args, options) do
|
||||
# Escape % characters to prevent ImageMagick from interpreting them as property variables
|
||||
comment =
|
||||
options
|
||||
|> Map.drop([:filepath, :link])
|
||||
|> Jason.encode!()
|
||||
|> inspect()
|
||||
|> String.replace("%", "%%")
|
||||
|
||||
args ++
|
||||
[
|
||||
"-set",
|
||||
"comment",
|
||||
inspect(Jason.encode!(Map.drop(options, [:filepath, :link]))),
|
||||
comment,
|
||||
options.filepath
|
||||
]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user