diff --git a/app/models/upload.rb b/app/models/upload.rb index 802be437e74..bf3d4155154 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -128,9 +128,7 @@ class Upload < ActiveRecord::Base end self.width, self.height = size = FastImage.new(path).size - if !size.blank? - self.thumbnail_width, self.thumbnail_height = ImageSizer.resize(*size) - end + self.thumbnail_width, self.thumbnail_height = ImageSizer.resize(*size) nil end diff --git a/lib/image_sizer.rb b/lib/image_sizer.rb index ee368ce3d1e..6e1646416cb 100644 --- a/lib/image_sizer.rb +++ b/lib/image_sizer.rb @@ -1,7 +1,7 @@ module ImageSizer # Resize an image to the aspect ratio we want - def self.resize(width, height, opts = {}) + def self.resize(width = nil, height = nil, opts = {}) return if width.blank? || height.blank? max_width = (opts[:max_width] || SiteSetting.max_image_width).to_f diff --git a/spec/components/image_sizer_spec.rb b/spec/components/image_sizer_spec.rb index b0132671016..f3c0960d79e 100644 --- a/spec/components/image_sizer_spec.rb +++ b/spec/components/image_sizer_spec.rb @@ -24,6 +24,10 @@ describe ImageSizer do expect(ImageSizer.resize('100', '101')).to eq([100, 101]) end + it 'returns nil if no width or height are provided' do + expect(ImageSizer.resize).to eq(nil) + end + describe 'when larger than the maximum width' do before do