FEATURE: new 'min ratio to crop' site setting

This commit is contained in:
Régis Hanol
2018-06-05 17:13:00 +02:00
parent f05ca02f13
commit dc61eaad37
3 changed files with 11 additions and 5 deletions

View File

@ -267,10 +267,6 @@ class CookedPostProcessor
rescue URI::InvalidURIError
end
# only crop when the image is taller than 18:9
# we only use 90% of that to allow for a small margin
MIN_RATIO_TO_CROP ||= (9.0 / 18.0) * 0.9
def convert_to_link!(img)
src = img["src"]
return if src.blank? || is_a_hyperlink?(img)
@ -288,7 +284,10 @@ class CookedPostProcessor
return if original_width <= width && original_height <= height
return if original_width <= SiteSetting.max_image_width && original_height <= SiteSetting.max_image_height
if crop = (original_width.to_f / original_height.to_f < MIN_RATIO_TO_CROP)
crop = SiteSetting.min_ratio_to_crop > 0
crop &&= original_width.to_f / original_height.to_f < SiteSetting.min_ratio_to_crop
if crop
width, height = ImageSizer.crop(original_width, original_height)
img["width"] = width
img["height"] = height