mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
fix apng encoding
This commit is contained in:
parent
be10ad4663
commit
41b3078da8
1 changed files with 14 additions and 7 deletions
|
@ -3,10 +3,11 @@ defmodule Philomena.Processors.Png do
|
|||
|
||||
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, dimensions, &1))
|
||||
scaled = Enum.flat_map(versions, &scale_if_smaller(file, animated?, dimensions, &1))
|
||||
|
||||
%{
|
||||
intensities: intensities,
|
||||
|
@ -35,13 +36,13 @@ defmodule Philomena.Processors.Png do
|
|||
optimized
|
||||
end
|
||||
|
||||
defp scale_if_smaller(_file, _dimensions, {:full, _target_dim}) do
|
||||
defp scale_if_smaller(_file, _animated?, _dimensions, {:full, _target_dim}) do
|
||||
[{:symlink_original, "full.png"}]
|
||||
end
|
||||
|
||||
defp scale_if_smaller(file, {width, height}, {thumb_name, {target_width, target_height}}) do
|
||||
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, {target_width, target_height})
|
||||
scaled = scale(file, animated?, {target_width, target_height})
|
||||
|
||||
[{:copy, scaled, "#{thumb_name}.png"}]
|
||||
else
|
||||
|
@ -49,16 +50,22 @@ defmodule Philomena.Processors.Png do
|
|||
end
|
||||
end
|
||||
|
||||
defp scale(file, {width, height}) do
|
||||
defp scale(file, animated?, {width, height}) do
|
||||
scaled = Briefly.create!(extname: ".png")
|
||||
|
||||
scale_filter =
|
||||
"scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease,format=rgb32"
|
||||
|
||||
{_output, 0} =
|
||||
System.cmd("ffmpeg", ["-loglevel", "0", "-y", "-i", file, "-vf", scale_filter, scaled])
|
||||
cond do
|
||||
animated? ->
|
||||
System.cmd("ffmpeg", ["-loglevel", "0", "-y", "-i", file, "-plays", "0", "-vf", scale_filter, "-f", "apng", scaled])
|
||||
|
||||
{_output, 0} = System.cmd("optipng", ["-i0", "-o1", "-quiet", "-clobber", scaled])
|
||||
true ->
|
||||
System.cmd("ffmpeg", ["-loglevel", "0", "-y", "-i", file, "-vf", scale_filter, scaled])
|
||||
end
|
||||
|
||||
System.cmd("optipng", ["-i0", "-o1", "-quiet", "-clobber", scaled])
|
||||
|
||||
scaled
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue