Skip to content

Commit

Permalink
fix thumbnail transparency preservation and save things as bigger by …
Browse files Browse the repository at this point in the history
…default (#800)

Fixes: #798
  • Loading branch information
zkat committed Apr 20, 2024
1 parent 430e402 commit 74696d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 6 additions & 7 deletions lib/banchan/workers/thumbnailer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ defmodule Banchan.Workers.Thumbnailer do
Uploads.gen_pending(
%User{id: upload.uploader_id},
upload,
"image/jpeg",
Keyword.get(opts, :name, "thumbnail.jpg")
"image/png",
Keyword.get(opts, :name, "thumbnail.png")
)
)
|> Ecto.Multi.run(:job, fn _repo, %{pending: pending} ->
Expand All @@ -58,9 +58,8 @@ defmodule Banchan.Workers.Thumbnailer do
src: upload.id,
dest: pending.id,
opts: %{
target_size: Keyword.get(opts, :target_size),
format: Keyword.get(opts, :format, "jpeg"),
dimensions: Keyword.get(opts, :dimensions)
dimensions: Keyword.get(opts, :dimensions),
upscale: Keyword.get(opts, :upscale)
}
})
)
Expand Down Expand Up @@ -106,15 +105,15 @@ defmodule Banchan.Workers.Thumbnailer do
if Uploads.video?(src) do
duration = FFprobe.duration(tmp_src)

output_src = Path.join([System.tmp_dir!(), src.key <> ".jpeg"])
output_src = Path.join([System.tmp_dir!(), src.key <> ".png"])

command =
FFmpex.new_command()
|> add_global_option(option_y())
|> add_input_file(tmp_src)
|> add_output_file(output_src)
|> add_file_option(option_f("image2"))
|> add_file_option(option_filter("scale=128:128"))
|> add_file_option(option_filter("scale=512:512"))
|> add_file_option(option_ss(round(duration / 2)))
|> add_file_option(option_vframes(1))

Expand Down
6 changes: 4 additions & 2 deletions lib/banchan/works/works.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Banchan.Works do
|> Enum.map(fn {%Upload{} = upload, index} ->
preview_id =
if Uploads.media?(upload) do
{:ok, %Upload{id: preview_id}} = Thumbnailer.thumbnail(upload)
{:ok, %Upload{id: preview_id}} = Thumbnailer.thumbnail(upload, dimensions: 1024)
preview_id
end

Expand Down Expand Up @@ -487,7 +487,9 @@ defmodule Banchan.Works do
|> Enum.map(fn {%Upload{} = upload, index} ->
preview_id =
if Uploads.media?(upload) do
{:ok, %Upload{id: preview_id}} = Thumbnailer.thumbnail(upload)
{:ok, %Upload{id: preview_id}} =
Thumbnailer.thumbnail(upload, dimensions: 1024)

preview_id
end

Expand Down

0 comments on commit 74696d0

Please sign in to comment.