tests courtesy of Claude

This commit is contained in:
Gavin McDonald
2025-10-13 08:24:31 -04:00
parent 96c01487f4
commit 070abb6b2e
7 changed files with 1019 additions and 4 deletions

View File

@@ -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