mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
19 lines
457 B
Ruby
19 lines
457 B
Ruby
module ImageSizer
|
|
|
|
# Resize an image to the aspect ratio we want
|
|
def self.resize(width, height)
|
|
return if width.blank? || height.blank?
|
|
|
|
max_width = SiteSetting.max_image_width.to_f
|
|
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;
|
|
[(w * ratio).floor, (h * ratio).floor]
|
|
end
|
|
|
|
end
|