DEV: Allow for taller images in posts and oneboxes (#15395)

The previous default aspect ratio for cropping tall images was a little
too strict and was cutting off images. This new setting should allow for
a larger range of image sizes before cropping them.
This commit is contained in:
Blake Erickson 2021-12-22 16:01:34 -07:00 committed by GitHub
parent 19089f21d2
commit b705971d42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View File

@ -1431,7 +1431,7 @@ files:
strip_image_metadata: true strip_image_metadata: true
min_ratio_to_crop: min_ratio_to_crop:
type: float type: float
default: 0.45 # 90% of 18:9 default: 0.22
min: 0 min: 0
max: 1 max: 1
simultaneous_uploads: simultaneous_uploads:

View File

@ -535,8 +535,32 @@ describe CookedPostProcessor do
end end
end end
context "with tall images" do context "with tall images > default aspect ratio" do
fab!(:upload) { Fabricate(:image_upload, width: 860, height: 2000) } fab!(:upload) { Fabricate(:image_upload, width: 500, height: 2200) }
fab!(:post) do
Fabricate(:post, raw: <<~HTML)
<img src="#{upload.url}">
HTML
end
let(:cpp) { CookedPostProcessor.new(post, disable_loading_image: true) }
before do
SiteSetting.create_thumbnails = true
end
it "resizes the image instead of crop" do
cpp.post_process
expect(cpp.html).to match(/width="113" height="500">/)
expect(cpp).to be_dirty
end
end
context "with taller images < default aspect ratio" do
fab!(:upload) { Fabricate(:image_upload, width: 500, height: 2300) }
fab!(:post) do fab!(:post) do
Fabricate(:post, raw: <<~HTML) Fabricate(:post, raw: <<~HTML)
@ -553,7 +577,7 @@ describe CookedPostProcessor do
it "crops the image" do it "crops the image" do
cpp.post_process cpp.post_process
expect(cpp.html).to match(/width="690" height="500">/) expect(cpp.html).to match(/width="500" height="500">/)
expect(cpp).to be_dirty expect(cpp).to be_dirty
end end