mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
FIX: should_alter_quality should respect png_to_jpg_quality (#12055)
`convert_to_jpeg!` is only called if `convert_png_to_jpeg?` and/or `should_alter_quality?` is true. `convert_png_to_jpeg?` can be disabled by setting `SiteSetting.png_to_jpg_quality` to 100. However, `should_alter_quality?` could be true if `SiteSetting.recompress_original_jpg_quality` was lower than the quality of the uploaded file, regardless of file type. This commits changes `should_alter_quality?` so that uploaded png files will use the `SiteSetting.png_to_jpg_quality` value, rather than ``SiteSetting.recompress_original_jpg_quality` value.
This commit is contained in:
parent
5d8673321f
commit
70050a8ba3
|
@ -276,7 +276,8 @@ class UploadCreator
|
|||
def should_alter_quality?
|
||||
return false if animated?
|
||||
|
||||
@upload.target_image_quality(@file.path, SiteSetting.recompress_original_jpg_quality).present?
|
||||
desired_quality = @image_info.type == :png ? SiteSetting.png_to_jpg_quality : SiteSetting.recompress_original_jpg_quality
|
||||
@upload.target_image_quality(@file.path, desired_quality).present?
|
||||
end
|
||||
|
||||
def should_downsize?
|
||||
|
|
Before Width: | Height: | Size: 412 KiB After Width: | Height: | Size: 412 KiB |
|
@ -134,6 +134,9 @@ RSpec.describe UploadCreator do
|
|||
let(:small_filename) { "logo.png" }
|
||||
let(:small_file) { file_from_fixtures(small_filename) }
|
||||
|
||||
let(:large_filename) { "large_and_unoptimized.png" }
|
||||
let(:large_file) { file_from_fixtures(large_filename) }
|
||||
|
||||
let(:animated_filename) { "animated.gif" }
|
||||
let(:animated_file) { file_from_fixtures(animated_filename) }
|
||||
|
||||
|
@ -212,6 +215,23 @@ RSpec.describe UploadCreator do
|
|||
expect(upload.original_filename).to eq('animated.gif')
|
||||
end
|
||||
|
||||
context "png image quality settings" do
|
||||
before do
|
||||
SiteSetting.png_to_jpg_quality = 100
|
||||
SiteSetting.recompress_original_jpg_quality = 90
|
||||
SiteSetting.image_preview_jpg_quality = 10
|
||||
end
|
||||
|
||||
it "should not convert to jpeg when png_to_jpg_quality is 100" do
|
||||
upload = UploadCreator.new(large_file, large_filename, force_optimize: true).create_for(user.id)
|
||||
|
||||
expect(upload.extension).to eq('png')
|
||||
expect(File.extname(upload.url)).to eq('.png')
|
||||
expect(upload.original_filename).to eq('large_and_unoptimized.png')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'should not convert animated WEBP images' do
|
||||
expect do
|
||||
UploadCreator.new(animated_webp_file, animated_webp_filename,
|
||||
|
|
Loading…
Reference in New Issue
Block a user