mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-01 03:46:44 +01:00
update image size after optimization
This commit is contained in:
parent
bdee305936
commit
df3467df7b
2 changed files with 14 additions and 8 deletions
|
@ -158,13 +158,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])
|
|> cast(attrs, [:image_sha512_hash, :image_size])
|
||||||
|> 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])
|
|> cast(attrs, [:image_sha512_hash, :image_size])
|
||||||
|> change(processed: true)
|
|> change(processed: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,11 @@ defmodule Philomena.Images.Thumbnailer do
|
||||||
{:ok, analysis} = Analyzers.analyze(file)
|
{:ok, analysis} = Analyzers.analyze(file)
|
||||||
|
|
||||||
apply_edit_script(image, Processors.process(analysis, file, @versions))
|
apply_edit_script(image, Processors.process(analysis, file, @versions))
|
||||||
recompute_sha512(image, file, &Image.thumbnail_changeset/2)
|
recompute_meta(image, file, &Image.thumbnail_changeset/2)
|
||||||
generate_dupe_reports(image)
|
generate_dupe_reports(image)
|
||||||
|
|
||||||
apply_edit_script(image, Processors.post_process(analysis, file))
|
apply_edit_script(image, Processors.post_process(analysis, file))
|
||||||
recompute_sha512(image, file, &Image.process_changeset/2)
|
recompute_meta(image, file, &Image.process_changeset/2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,12 +58,18 @@ defmodule Philomena.Images.Thumbnailer do
|
||||||
do: symlink(image_file(image), Path.join(thumb_dir, destination))
|
do: symlink(image_file(image), Path.join(thumb_dir, destination))
|
||||||
|
|
||||||
|
|
||||||
defp recompute_sha512(image, file, changeset_fn),
|
|
||||||
do: Repo.update!(changeset_fn.(image, %{"image_sha512_hash" => Sha512.file(file)}))
|
|
||||||
|
|
||||||
defp generate_dupe_reports(image),
|
defp generate_dupe_reports(image),
|
||||||
do: DuplicateReports.generate_reports(image)
|
do: DuplicateReports.generate_reports(image)
|
||||||
|
|
||||||
|
defp recompute_meta(image, file, changeset_fn) do
|
||||||
|
image
|
||||||
|
|> changeset_fn.(%{
|
||||||
|
"image_sha512_hash" => Sha512.file(file),
|
||||||
|
"image_size" => File.stat!(file).size
|
||||||
|
})
|
||||||
|
|> Repo.update!()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# Copy from source to destination, creating parent directories along
|
# Copy from source to destination, creating parent directories along
|
||||||
# the way and setting the appropriate permission bits when necessary.
|
# the way and setting the appropriate permission bits when necessary.
|
||||||
|
|
Loading…
Reference in a new issue