lib/fiona7/scrivito_patches/binary.rb in infopark_fiona7-1.5.5.4.0 vs lib/fiona7/scrivito_patches/binary.rb in infopark_fiona7-1.5.5.4.1

- old
+ new

@@ -148,11 +148,11 @@ (self.mime_type =~ /image\//) && (!self.width.present? || (1..4096).include?(self.width.to_i)) && (!self.height.present? || (1..4096).include?(self.height.to_i)) && ((0..100).include?(self.quality.to_i)) && (!self.fit.present? || ( - (self.fit == 'clip' || self.fit == 'crop') && + (self.fit == 'clip' || self.fit == 'crop' || self.fit == 'resize') && (self.width.to_i + self.height.to_i < 4096) && (self.fit == 'clip' || (self.width.present? && self.height.present?)) )) end @@ -169,20 +169,22 @@ Rails.logger.debug("Transforming image") end image = MiniMagick::Image.open(original_filepath) - if self.fit.blank? + fit = self.fit_with_default + + if fit.blank? image.combine_options do |b| b.quality self.quality.to_i end - elsif self.fit == 'clip' + elsif fit == 'clip' || fit == 'resize' image.combine_options do |b| b.resize "#{self.width}x#{self.height}>" b.quality self.quality.to_i end - elsif self.fit == 'crop' + elsif fit == 'crop' image.combine_options do |b| b.resize "#{self.width}x#{self.height}^" b.gravity self.gravity b.extent "#{self.width}x#{self.height}>" b.quality self.quality.to_i @@ -234,10 +236,14 @@ end def fit self.transformation_with_fallback[:fit] end + + def fit_with_default + self.fit || ((width.present? || height.present?) && 'resize') || nil + end end delegate :valid?, :present?, :filename, :filepath, :mime_type, :length, :last_changed, @@ -350,10 +356,10 @@ end def transformation_from_params if self.request.query_string ParamEncoder.new.decode( - ::CGI.parse(self.request.query_string)["t"] + ::CGI.parse(self.request.query_string)["t"].try(:first) ) end end def simple_set_header(name, value)