Fix truncated images

This commit is contained in:
href 2020-08-21 17:02:57 +00:00
parent aa0a5ffb48
commit 967afa064b

View file

@ -19,14 +19,24 @@ def ffmpeg_resize(uri_or_path, %{max_width: max_width, max_height: max_height} =
""" """
pid = Port.open({:spawn, cmd}, [:use_stdio, :in, :stream, :exit_status, :binary]) pid = Port.open({:spawn, cmd}, [:use_stdio, :in, :stream, :exit_status, :binary])
loop_recv(pid)
end
defp loop_recv(pid) do
loop_recv(pid, <<>>)
end
defp loop_recv(pid, acc) do
receive do receive do
{^pid, {:data, data}} -> {^pid, {:data, data}} ->
send(pid, {self(), :close}) loop_recv(pid, acc <> data)
{:ok, data}
{^pid, {:exit_status, status}} when status > 0 -> {^pid, {:exit_status, 0}} ->
{:ok, acc}
{^pid, {:exit_status, status}} ->
{:error, status} {:error, status}
end end
end end
end end