mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:37:02 +08:00
UX: only crops images taller than 18:9 instead of 16:9
This commit is contained in:
@ -247,9 +247,9 @@ class CookedPostProcessor
|
|||||||
rescue URI::InvalidURIError
|
rescue URI::InvalidURIError
|
||||||
end
|
end
|
||||||
|
|
||||||
# only crop when the image is taller than 16:9
|
# only crop when the image is taller than 18:9
|
||||||
# we only use 95% of that to allow for a small margin
|
# we only use 90% of that to allow for a small margin
|
||||||
MIN_RATIO_TO_CROP ||= (9.0 / 16.0) * 0.95
|
MIN_RATIO_TO_CROP ||= (9.0 / 18.0) * 0.9
|
||||||
|
|
||||||
def convert_to_link!(img)
|
def convert_to_link!(img)
|
||||||
src = img["src"]
|
src = img["src"]
|
||||||
@ -268,11 +268,7 @@ class CookedPostProcessor
|
|||||||
return if original_width <= width && original_height <= height
|
return if original_width <= width && original_height <= height
|
||||||
return if original_width <= SiteSetting.max_image_width && original_height <= SiteSetting.max_image_height
|
return 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
|
if 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
|
|
||||||
width, height = ImageSizer.crop(original_width, original_height)
|
width, height = ImageSizer.crop(original_width, original_height)
|
||||||
img["width"] = width
|
img["width"] = width
|
||||||
img["height"] = height
|
img["height"] = height
|
||||||
|
@ -180,7 +180,7 @@ describe CookedPostProcessor do
|
|||||||
SiteSetting.create_thumbnails = true
|
SiteSetting.create_thumbnails = true
|
||||||
|
|
||||||
Upload.expects(:get_from_url).returns(upload)
|
Upload.expects(:get_from_url).returns(upload)
|
||||||
FastImage.expects(:size).returns([860, 1900])
|
FastImage.expects(:size).returns([860, 2000])
|
||||||
OptimizedImage.expects(:resize).never
|
OptimizedImage.expects(:resize).never
|
||||||
OptimizedImage.expects(:crop).returns(true)
|
OptimizedImage.expects(:crop).returns(true)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user