From ebd4b4577168644ff1132af85215bfa2034ecdbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 26 May 2016 19:02:31 +0200 Subject: [PATCH] FIX: use 16:9 ratio to detect whether to crop a thumbnail or not --- lib/cooked_post_processor.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 60af2b57a..9d9e1fac3 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -186,6 +186,10 @@ class CookedPostProcessor rescue URI::InvalidURIError end + # only crop when the image is taller than 16:9 + # we only use 95% of that to allow for a small margin + MIN_RATIO_TO_CROP ||= (9.0 / 16.0) * 0.95 + def convert_to_link!(img) src = img["src"] return unless src.present? @@ -208,7 +212,7 @@ class CookedPostProcessor return if is_a_hyperlink?(img) crop = false - if original_width.to_f / original_height.to_f < 0.75 + if original_width.to_f / original_height.to_f < MIN_RATIO_TO_CROP crop = true width, height = ImageSizer.crop(original_width, original_height) img["width"] = width