end
end
+ defp prepare_image_resize_args(
+ %{max_width: max_width, max_height: max_height, format: "png"} = options
+ ) do
+ quality = options[:quality] || 85
+ resize = Enum.join([max_width, "x", max_height, ">"])
+
+ args = [
+ "-resize",
+ resize,
+ "-quality",
+ to_string(quality),
+ "png:-"
+ ]
+
+ {:ok, args}
+ end
+
defp prepare_image_resize_args(%{max_width: max_width, max_height: max_height} = options) do
quality = options[:quality] || 85
resize = Enum.join([max_width, "x", max_height, ">"])
redirect(conn, external: mediaproxy_url)
end
+ defp handle_preview("image/png" <> _ = _content_type, conn, url) do
+ handle_png_preview(conn, url)
+ end
+
defp handle_preview("image/" <> _ = _content_type, conn, url) do
- handle_image_preview(conn, url)
+ handle_jpeg_preview(conn, url)
end
defp handle_preview("video/" <> _ = _content_type, conn, url) do
send_resp(conn, :unprocessable_entity, "Unsupported content type: #{content_type}.")
end
- defp handle_image_preview(%{params: params} = conn, url) do
+ defp handle_png_preview(%{params: params} = conn, url) do
+ quality = Config.get!([:media_preview_proxy, :image_quality])
+
+ with {thumbnail_max_width, thumbnail_max_height} <- thumbnail_max_dimensions(params),
+ {:ok, thumbnail_binary} <-
+ MediaHelper.image_resize(
+ url,
+ %{
+ max_width: thumbnail_max_width,
+ max_height: thumbnail_max_height,
+ quality: quality,
+ format: "png"
+ }
+ ) do
+ conn
+ |> put_resp_header("content-type", "image/png")
+ |> put_resp_header("content-disposition", "inline; filename=\"preview.png\"")
+ |> send_resp(200, thumbnail_binary)
+ else
+ _ ->
+ send_resp(conn, :failed_dependency, "Can't handle preview.")
+ end
+ end
+
+ defp handle_jpeg_preview(%{params: params} = conn, url) do
quality = Config.get!([:media_preview_proxy, :image_quality])
with {thumbnail_max_width, thumbnail_max_height} <- thumbnail_max_dimensions(params),