diff options
author | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-05-08 23:06:47 +0300 |
---|---|---|
committer | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-05-08 23:06:47 +0300 |
commit | bbdad8556861c60ae1f526f63de9c5857c4ad547 (patch) | |
tree | 035b1b10142468c6acb565d0cd427c48f19652af /lib/pleroma/helpers | |
parent | 3a014dd6095b3096d4e7bc8e16908e8b70ad8b96 (diff) | |
download | pleroma-bbdad8556861c60ae1f526f63de9c5857c4ad547.tar.gz |
Initial implementation of image preview proxy. Media proxy tests refactoring.
Diffstat (limited to 'lib/pleroma/helpers')
-rw-r--r-- | lib/pleroma/helpers/mogrify_helper.ex | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/pleroma/helpers/mogrify_helper.ex b/lib/pleroma/helpers/mogrify_helper.ex new file mode 100644 index 000000000..67edb35c3 --- /dev/null +++ b/lib/pleroma/helpers/mogrify_helper.ex @@ -0,0 +1,25 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Helpers.MogrifyHelper do + @moduledoc """ + Handles common Mogrify operations. + """ + + @spec store_as_temporary_file(String.t(), binary()) :: {:ok, String.t()} | {:error, atom()} + @doc "Stores binary content fetched from specified URL as a temporary file." + def store_as_temporary_file(url, body) do + path = Mogrify.temporary_path_for(%{path: url}) + with :ok <- File.write(path, body), do: {:ok, path} + end + + @spec store_as_temporary_file(String.t(), String.t()) :: Mogrify.Image.t() | any() + @doc "Modifies file at specified path by resizing to specified limit dimensions." + def in_place_resize_to_limit(path, resize_dimensions) do + path + |> Mogrify.open() + |> Mogrify.resize_to_limit(resize_dimensions) + |> Mogrify.save(in_place: true) + end +end |