discourse/lib/image_sizer.rb

18 lines
423 B
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
module ImageSizer
# Resize an image to the aspect ratio we want
2013-02-25 11:42:20 -05:00
def self.resize(width, height)
2013-02-05 14:16:51 -05:00
max_width = SiteSetting.max_image_width.to_f
return nil if width.blank? or height.blank?
2013-02-25 11:42:20 -05: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
# Using the maximum width, resize the heigh retaining the aspect ratio
[max_width.floor, (h * (max_width / w)).floor]
end
end