Avoid unnecessary module attributes
This commit is contained in:
@@ -1,17 +1,18 @@
|
|||||||
defmodule MusicLibrary.Records.Cover do
|
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
|
@size 600
|
||||||
|
|
||||||
@fallback_path Application.app_dir(:music_library, ["priv", "cover-not-found.jpg"])
|
def fallback_data, do: unquote(fallback_data)
|
||||||
|
|
||||||
@external_resource @fallback_path
|
|
||||||
|
|
||||||
@fallback_data File.read!(@fallback_path)
|
|
||||||
|
|
||||||
def fallback_data, do: @fallback_data
|
|
||||||
|
|
||||||
def resize(cover_data, size \\ @size) do
|
def resize(cover_data, size \\ @size) do
|
||||||
{:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(cover_data, size)
|
{:ok, thumb} = Operation.thumbnail_buffer(cover_data, size)
|
||||||
Vix.Vips.Image.write_to_buffer(thumb, ".jpg")
|
Image.write_to_buffer(thumb, ".jpg")
|
||||||
end
|
end
|
||||||
|
|
||||||
def hash(cover_data) do
|
def hash(cover_data) do
|
||||||
@@ -19,8 +20,8 @@ defmodule MusicLibrary.Records.Cover do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def correct_size?(cover_data) do
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user