From 81810d81620c079f4e581fc0206de88c56b1ca92 Mon Sep 17 00:00:00 2001 From: Dmitry Borisov Date: Fri, 25 Oct 2024 20:11:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D0=BB=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BE=D1=80=D0=B8=D0=B3=D0=B8=D0=BD=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D1=8F=D0=B5=D0=BC=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B8=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F.=20=D0=9F=D1=80=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B5=20=D0=BE=D1=80=D0=B8=D0=B3=D0=B8=D0=BD=D0=B0=D0=BB?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B3=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=D1=81=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/paperclip/attachment.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/paperclip/attachment.rb b/lib/paperclip/attachment.rb index e7e346a..1ac5f00 100644 --- a/lib/paperclip/attachment.rb +++ b/lib/paperclip/attachment.rb @@ -155,12 +155,22 @@ module Paperclip @dirty = true - post_process if post_processing && valid? + if post_processing && valid? + post_process + + # Reset the file size and image sizes if the original file was reprocessed. + if queued_for_write.dig(:original) && instance_read(:file_size) != queued_for_write[:original].size.to_i + instance_write(:file_size, queued_for_write[:original].size.to_i) + sizes = FastImage.size(queued_for_write[:original]) + if sizes && sizes[0] && sizes[1] + instance_write(:width, sizes[0]) + instance_write(:height, sizes[1]) + end + end + end updater = :"#{name}_file_name_will_change!" instance.send updater if instance.respond_to? updater - # Reset the file size if the original file was reprocessed. - instance_write(:file_size, queued_for_write[:original].size.to_i) ensure uploaded_file.close if close_uploaded_file validate