FIX: crop & optimize user background profile/card images

This commit is contained in:
Régis Hanol
2015-07-15 17:15:43 +02:00
parent 00aaa692ac
commit b0802abae2
9 changed files with 70 additions and 64 deletions

View File

@@ -1,18 +1,18 @@
module ImageSizer
# Resize an image to the aspect ratio we want
def self.resize(width, height)
def self.resize(width, height, opts = {})
return if width.blank? || height.blank?
max_width = SiteSetting.max_image_width.to_f
max_height = SiteSetting.max_image_height.to_f
max_width = (opts[:max_width] || SiteSetting.max_image_width).to_f
max_height = (opts[:max_height] || SiteSetting.max_image_height).to_f
w = width.to_f
h = height.to_f
return [w.floor, h.floor] if w <= max_width && h <= max_height
ratio = [max_width / w, max_height / h].min;
ratio = [max_width / w, max_height / h].min
[(w * ratio).floor, (h * ratio).floor]
end