A platform for community discussion. Free, open, simple.
UX: only crops images taller than 18:9 instead of 16:9
Régis Hanol7d2283167a82
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex 3582a42e464..e9637755f09 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -247,9 +247,9 @@ class CookedPostProcessorrescue URI::InvalidURIErrorend- # 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+ # 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.9def convert_to_link!(img)src = img["src"]@@ -268,11 +268,7 @@ class CookedPostProcessorreturn if original_width <= width && original_height <= heightreturn if original_width <= SiteSetting.max_image_width && original_height <= SiteSetting.max_image_height- crop = original_width.to_f / original_height.to_f < MIN_RATIO_TO_CROP- # prevent iPhone X screenshots from being cropped- crop &= original_width != 1125 && original_height != 2436-- if crop+ if crop = (original_width.to_f / original_height.to_f < MIN_RATIO_TO_CROP)width, height = ImageSizer.crop(original_width, original_height)img["width"] = widthimg["height"] = heightdiff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex b6bf69b1b0e..d2b90f5e4d7 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -180,7 +180,7 @@ describe CookedPostProcessor doSiteSetting.create_thumbnails = trueUpload.expects(:get_from_url).returns(upload)- FastImage.expects(:size).returns([860, 1900])+ FastImage.expects(:size).returns([860, 2000])OptimizedImage.expects(:resize).neverOptimizedImage.expects(:crop).returns(true)