text alignment for widthxheight images
This commit is contained in:
@@ -21,7 +21,7 @@ defmodule LabelmakerWeb.Tools do
|
||||
|> Map.new(fn {k, v} -> {String.to_atom(k), v} end)
|
||||
|> Enum.map(fn
|
||||
{:align, align} ->
|
||||
{:align, process_alignment(align |> String.downcase())}
|
||||
{:align, align |> String.downcase()}
|
||||
|
||||
{:font, font} ->
|
||||
{:font, Constants.font_map()[String.downcase(font)]}
|
||||
@@ -35,9 +35,6 @@ defmodule LabelmakerWeb.Tools do
|
||||
{:label_too_long, _} ->
|
||||
{:label_too_long, String.length(parameters["label"]) > Constants.max_label_length()}
|
||||
|
||||
{:link, _} ->
|
||||
{:link, generate_link(parameters)}
|
||||
|
||||
{:preview_height, _} ->
|
||||
{:preview_height, calculate_preview_height(parameters)}
|
||||
|
||||
@@ -51,7 +48,7 @@ defmodule LabelmakerWeb.Tools do
|
||||
pair
|
||||
end)
|
||||
|> Enum.filter(fn
|
||||
{:align, align} -> align in Constants.permitted_gravity()
|
||||
{:align, align} -> align in Constants.permitted_alignments()
|
||||
{:color, color} -> color in Constants.colors()
|
||||
{:font, font} -> font in Map.values(Constants.font_map())
|
||||
{:outline, outline} -> outline in Constants.outlines()
|
||||
@@ -60,17 +57,21 @@ defmodule LabelmakerWeb.Tools do
|
||||
end)
|
||||
|> Map.new()
|
||||
|
||||
Map.merge(Constants.defaults(), parameters)
|
||||
parameters = Map.merge(Constants.defaults(), parameters)
|
||||
|
||||
Map.put(parameters, :link, generate_link(parameters))
|
||||
end
|
||||
|
||||
defp process_alignment("left"), do: "west"
|
||||
defp process_alignment("middle"), do: "center"
|
||||
defp process_alignment("right"), do: "east"
|
||||
defp process_alignment(alignment), do: alignment |> String.downcase()
|
||||
def process_gravity("left"), do: "west"
|
||||
def process_gravity("middle"), do: "center"
|
||||
def process_gravity("right"), do: "east"
|
||||
def process_gravity(alignment), do: alignment |> String.downcase()
|
||||
|
||||
defp process_height("", parameters) do
|
||||
parameters["width"] |> String.to_integer() |> max(0) |> min(Constants.max_height())
|
||||
end
|
||||
defp process_height("", _parameters), do: ""
|
||||
|
||||
# defp process_height("", parameters) do
|
||||
# parameters["width"] |> String.to_integer() |> max(0) |> min(Constants.max_height())
|
||||
# end
|
||||
|
||||
defp process_height(height, _parameters) do
|
||||
height |> String.to_integer() |> max(0) |> min(Constants.max_height())
|
||||
@@ -84,17 +85,19 @@ defmodule LabelmakerWeb.Tools do
|
||||
end
|
||||
end
|
||||
|
||||
defp generate_link(%{"height" => "", "label" => label, "width" => ""} = parameters) do
|
||||
~p"/#{label}?#{Map.take(parameters, ["color", "font", "outline", "size"])}"
|
||||
defp generate_link(%{height: "", label: label, width: ""} = parameters) do
|
||||
~p"/#{label}?#{Map.take(parameters, [:color, :font, :outline, :size])}"
|
||||
end
|
||||
|
||||
defp generate_link(%{"label" => label} = parameters) do
|
||||
~p"/#{label}?#{Map.take(parameters, ["color", "font", "height", "outline", "width"])}"
|
||||
defp generate_link(%{label: label} = parameters) do
|
||||
~p"/#{label}?#{Map.take(parameters, [:align, :color, :font, :height, :outline, :width])}"
|
||||
end
|
||||
|
||||
defp process_width("", parameters) do
|
||||
parameters["height"] |> String.to_integer() |> max(0) |> min(Constants.max_width())
|
||||
end
|
||||
defp process_width("", _parameters), do: ""
|
||||
|
||||
# defp process_width("", parameters) do
|
||||
# parameters["height"] |> String.to_integer() |> max(0) |> min(Constants.max_width())
|
||||
# end
|
||||
|
||||
defp process_width(width, _parameters) do
|
||||
width |> String.to_integer() |> max(0) |> min(Constants.max_width())
|
||||
|
||||
Reference in New Issue
Block a user