diff --git a/lib/music_library/records/cover.ex b/lib/music_library/records/cover.ex index 86e41b97..f6844ac6 100644 --- a/lib/music_library/records/cover.ex +++ b/lib/music_library/records/cover.ex @@ -1,17 +1,18 @@ defmodule MusicLibrary.Records.Cover do + alias Vix.Vips.{Image, Operation} + + fallback_path = Application.app_dir(:music_library, ["priv", "cover-not-found.jpg"]) + fallback_data = File.read!(fallback_path) + + @external_resource fallback_path + @size 600 - @fallback_path Application.app_dir(:music_library, ["priv", "cover-not-found.jpg"]) - - @external_resource @fallback_path - - @fallback_data File.read!(@fallback_path) - - def fallback_data, do: @fallback_data + def fallback_data, do: unquote(fallback_data) def resize(cover_data, size \\ @size) do - {:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(cover_data, size) - Vix.Vips.Image.write_to_buffer(thumb, ".jpg") + {:ok, thumb} = Operation.thumbnail_buffer(cover_data, size) + Image.write_to_buffer(thumb, ".jpg") end def hash(cover_data) do @@ -19,8 +20,8 @@ defmodule MusicLibrary.Records.Cover do end def correct_size?(cover_data) do - {:ok, image} = Vix.Vips.Image.new_from_buffer(cover_data) + {:ok, image} = Image.new_from_buffer(cover_data) - Vix.Vips.Image.width(image) == @size + Image.width(image) == @size end end