From a955a67b249ca7b107342c117f58e6d4ce2b1388 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sun, 27 Sep 2020 00:46:38 -0400 Subject: [PATCH] recalculate size on processing (derpibooru/philomena#206) --- lib/philomena/images/image.ex | 4 ++-- lib/philomena/images/thumbnailer.ex | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/philomena/images/image.ex b/lib/philomena/images/image.ex index 805267ff..31d622b3 100644 --- a/lib/philomena/images/image.ex +++ b/lib/philomena/images/image.ex @@ -195,13 +195,13 @@ defmodule Philomena.Images.Image do def thumbnail_changeset(image, attrs) do 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) end def process_changeset(image, attrs) do image - |> cast(attrs, [:image_sha512_hash, :image_size]) + |> cast(attrs, [:image_sha512_hash, :image_size, :image_width, :image_height]) |> change(processed: true) end diff --git a/lib/philomena/images/thumbnailer.ex b/lib/philomena/images/thumbnailer.ex index 46ea318b..5540a987 100644 --- a/lib/philomena/images/thumbnailer.ex +++ b/lib/philomena/images/thumbnailer.ex @@ -57,10 +57,14 @@ defmodule Philomena.Images.Thumbnailer do do: DuplicateReports.generate_reports(image) defp recompute_meta(image, file, changeset_fn) do + {:ok, %{dimensions: {width, height}}} = Analyzers.analyze(file) + image |> changeset_fn.(%{ "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!() end