Resize cover images to 400x400

This commit is contained in:
Claudio Ortolina
2024-09-17 10:39:49 +01:00
parent 1200215321
commit 5623a5239f
3 changed files with 26 additions and 1 deletions
+24 -1
View File
@@ -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()