mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
FIX: do not convert format for site setting uploads (#12410)
This commit is contained in:
parent
eda8a839d4
commit
64d2f260a9
|
@ -203,6 +203,7 @@ class UploadCreator
|
|||
MIN_CONVERT_TO_JPEG_SAVING_RATIO = 0.70
|
||||
|
||||
def convert_to_jpeg!
|
||||
return if @opts[:for_site_setting]
|
||||
return if filesize < MIN_CONVERT_TO_JPEG_BYTES_SAVED
|
||||
|
||||
jpeg_tempfile = Tempfile.new(["image", ".jpg"])
|
||||
|
|
|
@ -119,7 +119,6 @@ RSpec.describe UploadCreator do
|
|||
# pngquant will lose some colors causing some extra size reduction
|
||||
expect(thumbnail_size).to be < 7500
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'converting to jpeg' do
|
||||
|
@ -148,7 +147,6 @@ RSpec.describe UploadCreator do
|
|||
end
|
||||
|
||||
it 'should not store file as jpeg if it does not meet absolute byte saving requirements' do
|
||||
|
||||
# logo.png is 2297 bytes, converting to jpeg saves 30% but does not meet
|
||||
# the absolute savings required of 25_000 bytes, if you save less than that
|
||||
# skip this
|
||||
|
@ -165,7 +163,6 @@ RSpec.describe UploadCreator do
|
|||
expect(upload.extension).to eq('png')
|
||||
expect(File.extname(upload.url)).to eq('.png')
|
||||
expect(upload.original_filename).to eq('logo.png')
|
||||
|
||||
end
|
||||
|
||||
it 'should store the upload with the right extension' do
|
||||
|
@ -183,6 +180,14 @@ RSpec.describe UploadCreator do
|
|||
expect(upload.original_filename).to eq('should_be_jpeg.jpg')
|
||||
end
|
||||
|
||||
it "should not convert to jpeg when the image is uploaded from site setting" do
|
||||
upload = UploadCreator.new(large_file, large_filename, for_site_setting: true, 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
|
||||
|
||||
context "jpeg image quality settings" do
|
||||
before do
|
||||
SiteSetting.png_to_jpg_quality = 75
|
||||
|
@ -229,7 +234,6 @@ RSpec.describe UploadCreator do
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user