Try specifying fd0, force jpg out
[akkoma] / lib / pleroma / helpers / media_helper.ex
index 89dd4204bdd6e7c9f508c03f111472a69cf6c5e6..01f42d9b03f164ae2541b0637b687d0417d3822d 100644 (file)
@@ -7,18 +7,17 @@ defmodule Pleroma.Helpers.MediaHelper do
   Handles common media-related operations.
   """
 
-  def ffmpeg_resize(uri_or_path, %{max_width: max_width, max_height: max_height} = options) do
-    quality = options[:quality] || 1
+  def image_resize(url, %{max_width: max_width, max_height: max_height} = options) do
+    quality = options[:quality] || 85
 
     cmd = ~s"""
-    ffmpeg -i #{uri_or_path} -f lavfi -i color=c=white \
-      -filter_complex "[0:v] scale='min(#{max_width},iw)':'min(#{max_height},ih)': \
-        force_original_aspect_ratio=decrease [scaled]; \
-        [1][scaled] scale2ref [bg][img]; [bg] setsar=1 [bg]; [bg][img] overlay=shortest=1" \
-      -loglevel quiet -f image2 -vcodec mjpeg -frames:v 1 -q:v #{quality} pipe:1
+    convert fd:0 -resize '#{max_width}x#{max_height}>' -quality #{quality} jpg:-
     """
 
-    pid = Port.open({:spawn, cmd}, [:use_stdio, :in, :stream, :exit_status, :binary])
+    pid = Port.open({:spawn, cmd}, [:use_stdio, :stream, :exit_status, :binary])
+    {:ok, env} = url |> Pleroma.Web.MediaProxy.url() |> Pleroma.HTTP.get()
+    image = env.body
+    Port.command(pid, image)
     loop_recv(pid)
   end