mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 07:37:55 +08:00
FEATURE: new 'min ratio to crop' site setting
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user