lib/carrierwave/processing/mini_magick.rb in carrierwave-0.6.2 vs lib/carrierwave/processing/mini_magick.rb in carrierwave-0.7.0
- old
+ new
@@ -167,13 +167,20 @@
def resize_to_fill(width, height, gravity = 'Center')
manipulate! do |img|
cols, rows = img[:dimensions]
img.combine_options do |cmd|
if width != cols || height != rows
- scale = [width/cols.to_f, height/rows.to_f].max
- cols = (scale * (cols + 0.5)).round
- rows = (scale * (rows + 0.5)).round
- cmd.resize "#{cols}x#{rows}"
+ scale_x = width/cols.to_f
+ scale_y = height/rows.to_f
+ if scale_x >= scale_y
+ cols = (scale_x * (cols + 0.5)).round
+ rows = (scale_x * (rows + 0.5)).round
+ cmd.resize "#{cols}"
+ else
+ cols = (scale_y * (cols + 0.5)).round
+ rows = (scale_y * (rows + 0.5)).round
+ cmd.resize "x#{rows}"
+ end
end
cmd.gravity gravity
cmd.background "rgba(255,255,255,0.0)"
cmd.extent "#{width}x#{height}" if cols != width || rows != height
end