Skip to content

Commit 74696d0

Browse files
authored
fix thumbnail transparency preservation and save things as bigger by default (#800)
Fixes: #798
1 parent 430e402 commit 74696d0

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/banchan/workers/thumbnailer.ex

+6-7
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ defmodule Banchan.Workers.Thumbnailer do
4848
Uploads.gen_pending(
4949
%User{id: upload.uploader_id},
5050
upload,
51-
"image/jpeg",
52-
Keyword.get(opts, :name, "thumbnail.jpg")
51+
"image/png",
52+
Keyword.get(opts, :name, "thumbnail.png")
5353
)
5454
)
5555
|> Ecto.Multi.run(:job, fn _repo, %{pending: pending} ->
@@ -58,9 +58,8 @@ defmodule Banchan.Workers.Thumbnailer do
5858
src: upload.id,
5959
dest: pending.id,
6060
opts: %{
61-
target_size: Keyword.get(opts, :target_size),
62-
format: Keyword.get(opts, :format, "jpeg"),
63-
dimensions: Keyword.get(opts, :dimensions)
61+
dimensions: Keyword.get(opts, :dimensions),
62+
upscale: Keyword.get(opts, :upscale)
6463
}
6564
})
6665
)
@@ -106,15 +105,15 @@ defmodule Banchan.Workers.Thumbnailer do
106105
if Uploads.video?(src) do
107106
duration = FFprobe.duration(tmp_src)
108107

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

111110
command =
112111
FFmpex.new_command()
113112
|> add_global_option(option_y())
114113
|> add_input_file(tmp_src)
115114
|> add_output_file(output_src)
116115
|> add_file_option(option_f("image2"))
117-
|> add_file_option(option_filter("scale=128:128"))
116+
|> add_file_option(option_filter("scale=512:512"))
118117
|> add_file_option(option_ss(round(duration / 2)))
119118
|> add_file_option(option_vframes(1))
120119

lib/banchan/works/works.ex

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ defmodule Banchan.Works do
4747
|> Enum.map(fn {%Upload{} = upload, index} ->
4848
preview_id =
4949
if Uploads.media?(upload) do
50-
{:ok, %Upload{id: preview_id}} = Thumbnailer.thumbnail(upload)
50+
{:ok, %Upload{id: preview_id}} = Thumbnailer.thumbnail(upload, dimensions: 1024)
5151
preview_id
5252
end
5353

@@ -487,7 +487,9 @@ defmodule Banchan.Works do
487487
|> Enum.map(fn {%Upload{} = upload, index} ->
488488
preview_id =
489489
if Uploads.media?(upload) do
490-
{:ok, %Upload{id: preview_id}} = Thumbnailer.thumbnail(upload)
490+
{:ok, %Upload{id: preview_id}} =
491+
Thumbnailer.thumbnail(upload, dimensions: 1024)
492+
491493
preview_id
492494
end
493495

0 commit comments

Comments
 (0)