legendary-doc-site/apps/content/lib/content/attachment.ex

41 lines
923 B
Elixir
Raw Normal View History

defmodule Legendary.Content.Attachment do
2020-07-20 22:04:04 +00:00
@moduledoc """
Helpers for dealing with "attachment"-type posts, which are generally media
uploaded to the site e.g. images.
"""
alias Legendary.Content.Post
2020-07-20 22:04:04 +00:00
def dimensions(attachment) do
meta =
attachment
|> Post.metas_map
deserialization_results =
2020-07-28 15:54:24 +00:00
meta["attachment_metadata"]
2020-07-20 22:04:04 +00:00
|> PhpSerializer.unserialize
case deserialization_results do
{:ok, info} ->
%{
width: info |> Enum.find(fn {key, _} -> key == "width" end) |> elem(1),
height: info |> Enum.find(fn {key, _} -> key == "height" end) |> elem(1)
}
{:error, _} ->
nil
end
end
def vertical?(attachment) do
case dimensions(attachment) do
%{width: width, height: height} ->
if width < height do
true
else
false
end
_ ->
false
end
end
end