Resize cover images to 400x400
This commit is contained in:
@@ -64,12 +64,24 @@ defmodule MusicLibrary.Records.Importer do
|
||||
|
||||
def import_cover_image(record) do
|
||||
with {:ok, image_data} <- blob_get(record.image_url) do
|
||||
{:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(image_data, 400)
|
||||
{:ok, thumb_data} = Vix.Vips.Image.write_to_buffer(thumb, ".jpg")
|
||||
|
||||
record
|
||||
|> Rec.add_image_data(image_data)
|
||||
|> Rec.add_image_data(thumb_data)
|
||||
|> MusicLibrary.Repo.update!()
|
||||
end
|
||||
end
|
||||
|
||||
def resize_cover_image(record) do
|
||||
{:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(record.image_data, 400)
|
||||
{:ok, thumb_data} = Vix.Vips.Image.write_to_buffer(thumb, ".jpg")
|
||||
|
||||
record
|
||||
|> Rec.add_image_data(thumb_data)
|
||||
|> MusicLibrary.Repo.update!()
|
||||
end
|
||||
|
||||
def import_all_cover_images do
|
||||
Rec
|
||||
|> MusicLibrary.Repo.all()
|
||||
@@ -81,6 +93,17 @@ defmodule MusicLibrary.Records.Importer do
|
||||
end)
|
||||
end
|
||||
|
||||
def resize_all_cover_images do
|
||||
Rec
|
||||
|> MusicLibrary.Repo.all()
|
||||
|> Enum.each(fn r ->
|
||||
if r.image_data != nil do
|
||||
resize_cover_image(r)
|
||||
IO.puts("Resized cover image for #{r.title}")
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
def import_all do
|
||||
Rec
|
||||
|> MusicLibrary.Repo.all()
|
||||
|
||||
Reference in New Issue
Block a user