fix svg previewing

This commit is contained in:
byte[] 2020-05-28 19:55:18 -04:00
parent 64428907f5
commit 91ebd70966

View file

@ -1,12 +1,12 @@
defmodule Philomena.Processors.Svg do
alias Philomena.Intensities
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, preview, &1))
scaled = Enum.flat_map(versions, &scale_if_smaller(file, analysis.dimensions, preview, &1))
%{
intensities: intensities,
@ -29,14 +29,18 @@ defmodule Philomena.Processors.Svg do
preview
end
defp scale_if_smaller(_file, preview, {:full, _target_dim}) do
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, preview, {thumb_name, {target_width, target_height}}) do
scaled = scale(preview, {target_width, target_height})
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"}]
[{:copy, scaled, "#{thumb_name}.png"}]
else
[{:copy, preview, "#{thumb_name}.png"}]
end
end
defp scale(preview, {width, height}) do