2013-02-05 14:16:51 -05:00
|
|
|
module ImageSizer
|
|
|
|
|
|
|
|
# Resize an image to the aspect ratio we want
|
2013-02-25 19:42:20 +03:00
|
|
|
def self.resize(width, height)
|
2013-02-05 14:16:51 -05:00
|
|
|
max_width = SiteSetting.max_image_width.to_f
|
2013-06-15 12:29:20 +02:00
|
|
|
return if width.blank? || height.blank?
|
2013-02-25 19:42:20 +03:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
w = width.to_f
|
|
|
|
h = height.to_f
|
|
|
|
|
|
|
|
return [w.floor, h.floor] if w < max_width
|
|
|
|
|
2013-03-06 08:52:24 +01:00
|
|
|
# Using the maximum width, resize the height retaining the aspect ratio
|
2013-02-05 14:16:51 -05:00
|
|
|
[max_width.floor, (h * (max_width / w)).floor]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|