lib/fiona7/scrivito_patches/binary.rb in infopark_fiona7-1.5.4.3.0 vs lib/fiona7/scrivito_patches/binary.rb in infopark_fiona7-1.5.5.3.1
- old
+ new
@@ -144,17 +144,18 @@
protected
def valid_transformation?
true &&
(self.mime_type =~ /image\//) &&
- (self.width.present? || self.height.present?) &&
(!self.width.present? || (1..4096).include?(self.width.to_i)) &&
(!self.height.present? || (1..4096).include?(self.height.to_i)) &&
- ((1..75).include?(self.quality.to_i)) &&
- (self.fit == 'clip' || self.fit == 'crop') &&
- (self.width.to_i + self.height.to_i < 4096) &&
- (self.fit == 'clip' || (self.width.present? && self.height.present?))
+ ((0..100).include?(self.quality.to_i)) &&
+ (!self.fit.present? || (
+ (self.fit == 'clip' || self.fit == 'crop') &&
+ (self.width.to_i + self.height.to_i < 4096) &&
+ (self.fit == 'clip' || (self.width.present? && self.height.present?))
+ ))
end
def transformed_filepath
return @transformed_filepath if @transformed_filepath
return nil if self.original_filepath.nil?
@@ -168,19 +169,25 @@
Rails.logger.debug("Transforming image")
end
image = MiniMagick::Image.open(original_filepath)
- if self.fit == 'clip'
+ if self.fit.blank?
image.combine_options do |b|
+ b.quality self.quality.to_i
+ end
+ elsif self.fit == 'clip'
+ image.combine_options do |b|
b.resize "#{self.width}x#{self.height}>"
+ b.quality self.quality.to_i
end
elsif self.fit == 'crop'
image.combine_options do |b|
b.resize "#{self.width}x#{self.height}^"
- b.gravity "center"
+ b.gravity self.gravity
b.extent "#{self.width}x#{self.height}>"
+ b.quality self.quality.to_i
end
else
raise 'invalid fit'
end
@@ -188,17 +195,34 @@
@transformed_filepath = output_filepath
end
def transformed_filename
ext = ::File.extname(self.original_filepath)
- "#{self.fit}_#{self.width}_#{self.height}_#{self.quality}#{ext}"
+ "#{self.fit}_#{self.crop}_#{self.width}_#{self.height}_#{self.quality}#{ext}"
end
def transformation_with_fallback
@transformation_with_fallback ||= (self.transformation || {}).with_indifferent_access
end
+ CROP_TO_GRAVITY = {
+ 'center' => 'Center',
+ 'top' => 'North',
+ 'left' => 'West',
+ 'right' => 'East',
+ 'bottom' => 'South',
+ }.freeze
+
+
+ def crop
+ self.transformation_with_fallback[:crop].presence || 'center'
+ end
+
+ def gravity
+ CROP_TO_GRAVITY[self.crop] || 'Center'
+ end
+
def width
self.transformation_with_fallback[:width].to_s
end
def height
@@ -208,10 +232,10 @@
def quality
self.transformation_with_fallback[:quality] || '75'
end
def fit
- self.transformation_with_fallback[:fit] || 'clip'
+ self.transformation_with_fallback[:fit]
end
end
delegate :valid?, :present?,
:filename, :filepath,