Put updated sizes in the upload when resizing
Closes #823 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
16c52c3802
commit
70bb3f3dd7
@ -6,22 +6,27 @@ defmodule Mobilizon.Web.Upload.Filter.Resize do
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@behaviour Mobilizon.Web.Upload.Filter
|
@behaviour Mobilizon.Web.Upload.Filter
|
||||||
|
alias Mobilizon.Web.Upload
|
||||||
|
|
||||||
@maximum_width 1_920
|
@maximum_width 1_920
|
||||||
@maximum_height 1_080
|
@maximum_height 1_080
|
||||||
|
|
||||||
def filter(%Mobilizon.Web.Upload{
|
def filter(
|
||||||
tempfile: file,
|
%Upload{
|
||||||
content_type: "image" <> _,
|
tempfile: file,
|
||||||
width: width,
|
content_type: "image" <> _,
|
||||||
height: height
|
width: width,
|
||||||
}) do
|
height: height
|
||||||
|
} = upload
|
||||||
|
) do
|
||||||
|
{new_width, new_height} = sizes = limit_sizes({width, height})
|
||||||
|
|
||||||
file
|
file
|
||||||
|> Mogrify.open()
|
|> Mogrify.open()
|
||||||
|> Mogrify.resize(string(limit_sizes({width, height})))
|
|> Mogrify.resize(string(sizes))
|
||||||
|> Mogrify.save(in_place: true)
|
|> Mogrify.save(in_place: true)
|
||||||
|
|
||||||
{:ok, :filtered}
|
{:ok, :filtered, %Upload{upload | width: new_width, height: new_height}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter(_), do: {:ok, :noop}
|
def filter(_), do: {:ok, :noop}
|
||||||
|
Loading…
Reference in New Issue
Block a user