mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
Remove scale_if_smaller, no more symlinking
This commit is contained in:
parent
6e4771a57a
commit
1670fd9eb9
5 changed files with 24 additions and 116 deletions
|
@ -8,18 +8,18 @@ defmodule Philomena.Processors.Gif do
|
|||
end
|
||||
|
||||
def process(analysis, file, versions) do
|
||||
dimensions = analysis.dimensions
|
||||
duration = analysis.duration
|
||||
preview = preview(duration, file)
|
||||
palette = palette(file)
|
||||
|
||||
{:ok, intensities} = Intensities.file(preview)
|
||||
|
||||
scaled = Enum.flat_map(versions, &scale_if_smaller(palette, file, dimensions, &1))
|
||||
scaled = Enum.flat_map(versions, &scale(palette, file, &1))
|
||||
videos = generate_videos(file)
|
||||
|
||||
%{
|
||||
intensities: intensities,
|
||||
thumbnails: scaled ++ [{:copy, preview, "rendered.png"}]
|
||||
thumbnails: scaled ++ videos ++ [{:copy, preview, "rendered.png"}]
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -66,27 +66,7 @@ defmodule Philomena.Processors.Gif do
|
|||
palette
|
||||
end
|
||||
|
||||
# Generate full version, and WebM and MP4 previews
|
||||
defp scale_if_smaller(_palette, file, _dimensions, {:full, _target_dim}) do
|
||||
[{:symlink_original, "full.gif"}] ++ generate_videos(file)
|
||||
end
|
||||
|
||||
defp scale_if_smaller(
|
||||
palette,
|
||||
file,
|
||||
{width, height},
|
||||
{thumb_name, {target_width, target_height}}
|
||||
) do
|
||||
if width > target_width or height > target_height do
|
||||
scaled = scale(palette, file, {target_width, target_height})
|
||||
|
||||
[{:copy, scaled, "#{thumb_name}.gif"}]
|
||||
else
|
||||
[{:symlink_original, "#{thumb_name}.gif"}]
|
||||
end
|
||||
end
|
||||
|
||||
defp scale(palette, file, {width, height}) do
|
||||
defp scale(palette, file, {thumb_name, {width, height}}) do
|
||||
scaled = Briefly.create!(extname: ".gif")
|
||||
|
||||
scale_filter = "scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease"
|
||||
|
@ -110,7 +90,7 @@ defmodule Philomena.Processors.Gif do
|
|||
scaled
|
||||
])
|
||||
|
||||
scaled
|
||||
[{:copy, scaled, "#{thumb_name}.gif"}]
|
||||
end
|
||||
|
||||
defp generate_videos(file) do
|
||||
|
|
|
@ -5,13 +5,12 @@ defmodule Philomena.Processors.Jpeg do
|
|||
Enum.map(sizes, fn {name, _} -> "#{name}.jpg" end)
|
||||
end
|
||||
|
||||
def process(analysis, file, versions) do
|
||||
dimensions = analysis.dimensions
|
||||
def process(_analysis, file, versions) do
|
||||
stripped = optimize(strip(file))
|
||||
|
||||
{:ok, intensities} = Intensities.file(stripped)
|
||||
|
||||
scaled = Enum.flat_map(versions, &scale_if_smaller(stripped, dimensions, &1))
|
||||
scaled = Enum.flat_map(versions, &scale(stripped, &1))
|
||||
|
||||
%{
|
||||
replace_original: stripped,
|
||||
|
@ -72,21 +71,7 @@ defmodule Philomena.Processors.Jpeg do
|
|||
optimized
|
||||
end
|
||||
|
||||
defp scale_if_smaller(_file, _dimensions, {:full, _target_dim}) do
|
||||
[{:symlink_original, "full.jpg"}]
|
||||
end
|
||||
|
||||
defp scale_if_smaller(file, {width, height}, {thumb_name, {target_width, target_height}}) do
|
||||
if width > target_width or height > target_height do
|
||||
scaled = scale(file, {target_width, target_height})
|
||||
|
||||
[{:copy, scaled, "#{thumb_name}.jpg"}]
|
||||
else
|
||||
[{:symlink_original, "#{thumb_name}.jpg"}]
|
||||
end
|
||||
end
|
||||
|
||||
defp scale(file, {width, height}) do
|
||||
defp scale(file, {thumb_name, {width, height}}) do
|
||||
scaled = Briefly.create!(extname: ".jpg")
|
||||
scale_filter = "scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease"
|
||||
|
||||
|
@ -106,7 +91,7 @@ defmodule Philomena.Processors.Jpeg do
|
|||
|
||||
{_output, 0} = System.cmd("jpegtran", ["-optimize", "-outfile", scaled, scaled])
|
||||
|
||||
scaled
|
||||
[{:copy, scaled, "#{thumb_name}.jpg"}]
|
||||
end
|
||||
|
||||
defp srgb_profile do
|
||||
|
|
|
@ -6,12 +6,11 @@ defmodule Philomena.Processors.Png do
|
|||
end
|
||||
|
||||
def process(analysis, file, versions) do
|
||||
dimensions = analysis.dimensions
|
||||
animated? = analysis.animated?
|
||||
|
||||
{:ok, intensities} = Intensities.file(file)
|
||||
|
||||
scaled = Enum.flat_map(versions, &scale_if_smaller(file, animated?, dimensions, &1))
|
||||
scaled = Enum.flat_map(versions, &scale(file, animated?, &1))
|
||||
|
||||
%{
|
||||
intensities: intensities,
|
||||
|
@ -47,26 +46,7 @@ defmodule Philomena.Processors.Png do
|
|||
optimized
|
||||
end
|
||||
|
||||
defp scale_if_smaller(_file, _animated?, _dimensions, {:full, _target_dim}) do
|
||||
[{:symlink_original, "full.png"}]
|
||||
end
|
||||
|
||||
defp scale_if_smaller(
|
||||
file,
|
||||
animated?,
|
||||
{width, height},
|
||||
{thumb_name, {target_width, target_height}}
|
||||
) do
|
||||
if width > target_width or height > target_height do
|
||||
scaled = scale(file, animated?, {target_width, target_height})
|
||||
|
||||
[{:copy, scaled, "#{thumb_name}.png"}]
|
||||
else
|
||||
[{:symlink_original, "#{thumb_name}.png"}]
|
||||
end
|
||||
end
|
||||
|
||||
defp scale(file, animated?, {width, height}) do
|
||||
defp scale(file, animated?, {thumb_name, {width, height}}) do
|
||||
scaled = Briefly.create!(extname: ".png")
|
||||
|
||||
scale_filter =
|
||||
|
@ -96,6 +76,6 @@ defmodule Philomena.Processors.Png do
|
|||
|
||||
System.cmd("optipng", ["-i0", "-o1", "-quiet", "-clobber", scaled])
|
||||
|
||||
scaled
|
||||
[{:copy, scaled, "#{thumb_name}.png"}]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,16 +7,17 @@ defmodule Philomena.Processors.Svg do
|
|||
|> Kernel.++(["rendered.png", "full.png"])
|
||||
end
|
||||
|
||||
def process(analysis, file, versions) do
|
||||
def process(_analysis, file, versions) do
|
||||
preview = preview(file)
|
||||
|
||||
{:ok, intensities} = Intensities.file(preview)
|
||||
|
||||
scaled = Enum.flat_map(versions, &scale_if_smaller(file, analysis.dimensions, preview, &1))
|
||||
scaled = Enum.flat_map(versions, &scale(preview, &1))
|
||||
full = [{:copy, preview, "full.png"}]
|
||||
|
||||
%{
|
||||
intensities: intensities,
|
||||
thumbnails: scaled ++ [{:copy, preview, "rendered.png"}]
|
||||
thumbnails: scaled ++ full ++ [{:copy, preview, "rendered.png"}]
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -35,26 +36,7 @@ defmodule Philomena.Processors.Svg do
|
|||
preview
|
||||
end
|
||||
|
||||
defp scale_if_smaller(_file, _dimensions, preview, {:full, _target_dim}) do
|
||||
[{:symlink_original, "full.svg"}, {:copy, preview, "full.png"}]
|
||||
end
|
||||
|
||||
defp scale_if_smaller(
|
||||
_file,
|
||||
{width, height},
|
||||
preview,
|
||||
{thumb_name, {target_width, target_height}}
|
||||
) do
|
||||
if width > target_width or height > target_height do
|
||||
scaled = scale(preview, {target_width, target_height})
|
||||
|
||||
[{:copy, scaled, "#{thumb_name}.png"}]
|
||||
else
|
||||
[{:copy, preview, "#{thumb_name}.png"}]
|
||||
end
|
||||
end
|
||||
|
||||
defp scale(preview, {width, height}) do
|
||||
defp scale(preview, {thumb_name, {width, height}}) do
|
||||
scaled = Briefly.create!(extname: ".png")
|
||||
scale_filter = "scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease"
|
||||
|
||||
|
@ -63,6 +45,6 @@ defmodule Philomena.Processors.Svg do
|
|||
|
||||
{_output, 0} = System.cmd("optipng", ["-i0", "-o1", "-quiet", "-clobber", scaled])
|
||||
|
||||
scaled
|
||||
[{:copy, scaled, "#{thumb_name}.png"}]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,13 +23,13 @@ defmodule Philomena.Processors.Webm do
|
|||
|
||||
{:ok, intensities} = Intensities.file(preview)
|
||||
|
||||
scaled =
|
||||
Enum.flat_map(versions, &scale_if_smaller(stripped, mp4, palette, duration, dimensions, &1))
|
||||
scaled = Enum.flat_map(versions, &scale(stripped, palette, duration, dimensions, &1))
|
||||
mp4 = [{:copy, mp4, "full.mp4"}]
|
||||
|
||||
%{
|
||||
replace_original: stripped,
|
||||
intensities: intensities,
|
||||
thumbnails: scaled ++ [{:copy, preview, "rendered.png"}]
|
||||
thumbnails: scaled ++ mp4 ++ [{:copy, preview, "rendered.png"}]
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -70,31 +70,12 @@ defmodule Philomena.Processors.Webm do
|
|||
stripped
|
||||
end
|
||||
|
||||
defp scale_if_smaller(_file, mp4, _palette, _duration, _dimensions, {:full, _target_dim}) do
|
||||
[
|
||||
{:symlink_original, "full.webm"},
|
||||
{:copy, mp4, "full.mp4"}
|
||||
]
|
||||
end
|
||||
|
||||
defp scale_if_smaller(
|
||||
file,
|
||||
mp4,
|
||||
palette,
|
||||
duration,
|
||||
{width, height},
|
||||
{thumb_name, {target_width, target_height}}
|
||||
) do
|
||||
{webm, mp4} =
|
||||
if width > target_width or height > target_height do
|
||||
scale_videos(file, {width, height}, {target_width, target_height})
|
||||
else
|
||||
{file, mp4}
|
||||
end
|
||||
defp scale(file, palette, duration, dimensions, {thumb_name, target_dimensions}) do
|
||||
{webm, mp4} = scale_videos(file, dimensions, target_dimensions)
|
||||
|
||||
cond do
|
||||
thumb_name in [:thumb, :thumb_small, :thumb_tiny] ->
|
||||
gif = scale_gif(file, palette, duration, {target_width, target_height})
|
||||
gif = scale_gif(file, palette, duration, target_dimensions)
|
||||
|
||||
[
|
||||
{:copy, webm, "#{thumb_name}.webm"},
|
||||
|
|
Loading…
Reference in a new issue