Update aspect ratio on dimension change

This commit is contained in:
Liam 2025-01-27 20:11:55 -05:00
parent 8e6e45d540
commit b24a252cb8
2 changed files with 16 additions and 3 deletions

View file

@ -235,13 +235,25 @@ defmodule Philomena.Images.Image do
def thumbnail_changeset(image, attrs) do
image
|> cast(attrs, [:image_sha512_hash, :image_size, :image_width, :image_height])
|> cast(attrs, [
:image_sha512_hash,
:image_size,
:image_width,
:image_height,
:image_aspect_ratio
])
|> change(thumbnails_generated: true, duplication_checked: true)
end
def process_changeset(image, attrs) do
image
|> cast(attrs, [:image_sha512_hash, :image_size, :image_width, :image_height])
|> cast(attrs, [
:image_sha512_hash,
:image_size,
:image_width,
:image_height,
:image_aspect_ratio
])
|> change(processed: true)
end

View file

@ -134,7 +134,8 @@ defmodule Philomena.Images.Thumbnailer do
"image_sha512_hash" => Sha512.file(file),
"image_size" => File.stat!(file).size,
"image_width" => width,
"image_height" => height
"image_height" => height,
"image_aspect_ratio" => width / height
})
|> Repo.update!()
end