1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Upload.Filter.AnalyzeMetadata do
7 Extracts metadata about the upload, such as width/height
11 @behaviour Pleroma.Upload.Filter
13 @spec filter(Pleroma.Upload.t()) ::
14 {:ok, :filtered, Pleroma.Upload.t()} | {:ok, :noop} | {:error, String.t()}
15 def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _} = upload) do
24 |> Map.put(:width, image.width)
25 |> Map.put(:height, image.height)
26 |> Map.put(:blurhash, get_blurhash(file))
28 {:ok, :filtered, upload}
31 Logger.warn("#{__MODULE__}: #{inspect(e)}")
36 def filter(_), do: {:ok, :noop}
38 defp get_blurhash(file) do
39 with {:ok, blurhash} <- :eblurhash.magick(file) do