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

@ -1342,6 +1342,8 @@ en:
strip_image_metadata: "Strip image metadata."
min_ratio_to_crop: "Ratio used to crop tall images. Enter the result of width / height."
enable_flash_video_onebox: "Enable embedding of swf and flv (Adobe Flash) links in oneboxes. WARNING: may introduce security risks."
default_invitee_trust_level: "Default trust level (0-4) for invited users."

View File

@ -941,6 +941,11 @@ files:
default: true
client: true
strip_image_metadata: true
min_ratio_to_crop:
type: float
default: 0.45 # 90% of 18:9
min: 0
max: 1
trust:
default_trust_level:

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