2024-06-02 06:15:09 +02:00
|
|
|
defmodule PhilomenaMedia.Analyzers.Svg do
|
|
|
|
@moduledoc false
|
|
|
|
|
|
|
|
alias PhilomenaMedia.Analyzers.Analyzer
|
|
|
|
alias PhilomenaMedia.Analyzers.Result
|
|
|
|
|
|
|
|
@behaviour Analyzer
|
|
|
|
|
|
|
|
@spec analyze(Path.t()) :: Result.t()
|
2019-11-26 01:06:40 +01:00
|
|
|
def analyze(file) do
|
2020-05-16 19:48:54 +02:00
|
|
|
stats = stats(file)
|
|
|
|
|
2024-06-02 06:15:09 +02:00
|
|
|
%Result{
|
2019-11-26 01:06:40 +01:00
|
|
|
extension: "svg",
|
|
|
|
mime_type: "image/svg+xml",
|
|
|
|
animated?: false,
|
|
|
|
duration: 0.0,
|
2020-05-16 19:48:54 +02:00
|
|
|
dimensions: stats.dimensions
|
2019-11-26 01:06:40 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-05-16 19:48:54 +02:00
|
|
|
defp stats(file) do
|
2021-10-24 03:55:32 +02:00
|
|
|
case System.cmd("svgstat", [file]) do
|
2019-11-26 01:06:40 +01:00
|
|
|
{output, 0} ->
|
2021-10-24 03:55:32 +02:00
|
|
|
[_size, _frames, width, height, _num, _den] =
|
2019-11-26 01:06:40 +01:00
|
|
|
output
|
|
|
|
|> String.trim()
|
|
|
|
|> String.split(" ")
|
|
|
|
|> Enum.map(&String.to_integer/1)
|
|
|
|
|
2020-05-16 19:48:54 +02:00
|
|
|
%{dimensions: {width, height}}
|
2019-11-26 01:06:40 +01:00
|
|
|
|
2020-05-16 19:48:54 +02:00
|
|
|
_ ->
|
|
|
|
%{dimensions: {0, 0}}
|
2019-11-26 01:06:40 +01:00
|
|
|
end
|
|
|
|
end
|
2020-01-11 05:20:19 +01:00
|
|
|
end
|