mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
recalculate size on processing (derpibooru/philomena#206)
This commit is contained in:
parent
02cbecb193
commit
a955a67b24
2 changed files with 7 additions and 3 deletions
|
@ -195,13 +195,13 @@ defmodule Philomena.Images.Image do
|
||||||
|
|
||||||
def thumbnail_changeset(image, attrs) do
|
def thumbnail_changeset(image, attrs) do
|
||||||
image
|
image
|
||||||
|> cast(attrs, [:image_sha512_hash, :image_size])
|
|> cast(attrs, [:image_sha512_hash, :image_size, :image_width, :image_height])
|
||||||
|> change(thumbnails_generated: true, duplication_checked: true)
|
|> change(thumbnails_generated: true, duplication_checked: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_changeset(image, attrs) do
|
def process_changeset(image, attrs) do
|
||||||
image
|
image
|
||||||
|> cast(attrs, [:image_sha512_hash, :image_size])
|
|> cast(attrs, [:image_sha512_hash, :image_size, :image_width, :image_height])
|
||||||
|> change(processed: true)
|
|> change(processed: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -57,10 +57,14 @@ defmodule Philomena.Images.Thumbnailer do
|
||||||
do: DuplicateReports.generate_reports(image)
|
do: DuplicateReports.generate_reports(image)
|
||||||
|
|
||||||
defp recompute_meta(image, file, changeset_fn) do
|
defp recompute_meta(image, file, changeset_fn) do
|
||||||
|
{:ok, %{dimensions: {width, height}}} = Analyzers.analyze(file)
|
||||||
|
|
||||||
image
|
image
|
||||||
|> changeset_fn.(%{
|
|> changeset_fn.(%{
|
||||||
"image_sha512_hash" => Sha512.file(file),
|
"image_sha512_hash" => Sha512.file(file),
|
||||||
"image_size" => File.stat!(file).size
|
"image_size" => File.stat!(file).size,
|
||||||
|
"image_width" => width,
|
||||||
|
"image_height" => height
|
||||||
})
|
})
|
||||||
|> Repo.update!()
|
|> Repo.update!()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue