def image_resize(url, options) do
with executable when is_binary(executable) <- System.find_executable("convert"),
- {:ok, args} <- prepare_resize_args(options),
+ {:ok, args} <- prepare_image_resize_args(options),
url = Pleroma.Web.MediaProxy.url(url),
{:ok, env} <- Pleroma.HTTP.get(url),
{:ok, fifo_path} <- mkfifo()
end
end
- defp prepare_resize_args(%{max_width: max_width, max_height: max_height} = options) do
+ 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, ">"])
args = [
+ "-interlace", "Plane",
"-resize", resize,
- "-quality", to_string(quality)
+ "-quality", to_string(quality),
+ "jpg:-"
]
{:ok, args}
end
- defp prepare_resize_args(_), do: {:error, :missing_options}
+ defp prepare_image_resize_args(_), do: {:error, :missing_options}
defp run_fifo(fifo_path, env, executable, args) do
- args = List.flatten([fifo_path, args, "jpg:fd:1"])
+ args = List.flatten([fifo_path, args])
pid = Port.open({:spawn_executable, executable}, [:use_stdio, :stream, :exit_status, :binary, args: args])
fifo = Port.open(to_charlist(fifo_path), [:eof, :binary, :stream, :out])
true = Port.command(fifo, env.body)