From 7e113870a7ede939e1ae1200454c8a14c0f9e775 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 27 Jun 2019 13:52:28 +0200 Subject: [PATCH] Bump rszr from 0.4.0 to 0.5.2 Bumps [rszr](https://github.com/mtgrosser/rszr) from 0.4.0 to 0.5.2. - [Release notes](https://github.com/mtgrosser/rszr/releases) - [Changelog](https://github.com/mtgrosser/rszr/blob/master/CHANGELOG.md) - [Commits](https://github.com/mtgrosser/rszr/compare/v0.4.0...v0.5.2) --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/models/store.rb | 30 ++++++++++-------------------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/Gemfile b/Gemfile index 260709821..ac5d22adf 100644 --- a/Gemfile +++ b/Gemfile @@ -123,7 +123,7 @@ gem 'rubyntlm', git: 'https://github.com/wimm/rubyntlm' gem 'viewpoint' # image processing -gem 'rszr', '0.4.0' +gem 'rszr', '0.5.2' # Gems used only for develop/test and not required # in production environments by default. diff --git a/Gemfile.lock b/Gemfile.lock index 601314e0d..34b6cda0a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -425,7 +425,7 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rszr (0.4.0) + rszr (0.5.2) rubocop (0.67.2) jaro_winkler (~> 1.5.1) parallel (~> 1.10) @@ -609,7 +609,7 @@ DEPENDENCIES rb-fsevent rchardet (>= 1.8.0) rspec-rails - rszr (= 0.4.0) + rszr (= 0.5.2) rubocop rubocop-performance rubocop-rspec diff --git a/app/models/store.rb b/app/models/store.rb index 4dd5c1a58..4b4b1019d 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -281,10 +281,6 @@ returns file.provider end - def self.semaphore - @semaphore ||= Mutex.new - end - private def image_resize(content, width) @@ -299,25 +295,19 @@ returns temp_file.binmode temp_file.write(content) temp_file.close + image = Rszr::Image.load(temp_file.path) - temp_file_resize = nil - self.class.semaphore.synchronize do - image = Rszr::Image.load(temp_file.path) + # do not resize image if image is smaller or already same size + return if image.width <= width - # do not resize image if image is smaller or already same size - return if image.width <= width - - # do not resize image if new height is smaller then 7px (images - # with small height are usally usefull to resize) - ratio = image.width / width - return if image.height / ratio <= 6 - - image.resize!(width, :auto) - temp_file_resize = ::Tempfile.new.path - image.save(temp_file_resize) - image.send(:handle).finalize! - end + # do not resize image if new height is smaller then 7px (images + # with small height are usally usefull to resize) + ratio = image.width / width + return if image.height / ratio <= 6 + image.resize!(width, :auto) + temp_file_resize = ::Tempfile.new.path + image.save(temp_file_resize) image_resized = ::File.binread(temp_file_resize) Cache.write(cache_key, image_resized, { expires_in: 6.months })