logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

exiftool.ex (1091B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Upload.Filter.Exiftool do
  5. @moduledoc """
  6. Strips GPS related EXIF tags and overwrites the file in place.
  7. Also strips or replaces filesystem metadata e.g., timestamps.
  8. """
  9. @behaviour Pleroma.Upload.Filter
  10. @spec filter(Pleroma.Upload.t()) :: {:ok, any()} | {:error, String.t()}
  11. # Formats not compatible with exiftool at this time
  12. def filter(%Pleroma.Upload{content_type: "image/heic"}), do: {:ok, :noop}
  13. def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop}
  14. def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
  15. try do
  16. case System.cmd("exiftool", ["-overwrite_original", "-gps:all=", file], parallelism: true) do
  17. {_response, 0} -> {:ok, :filtered}
  18. {error, 1} -> {:error, error}
  19. end
  20. rescue
  21. e in ErlangError ->
  22. {:error, "#{__MODULE__}: #{inspect(e)}"}
  23. end
  24. end
  25. def filter(_), do: {:ok, :noop}
  26. end