diff --git a/lib/philomena/processors/svg.ex b/lib/philomena/processors/svg.ex index 705cee34..663c0519 100644 --- a/lib/philomena/processors/svg.ex +++ b/lib/philomena/processors/svg.ex @@ -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