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
|
MIN_CONVERT_TO_JPEG_SAVING_RATIO = 0.70
|
||||||
|
|
||||||
def convert_to_jpeg!
|
def convert_to_jpeg!
|
||||||
|
return if @opts[:for_site_setting]
|
||||||
return if filesize < MIN_CONVERT_TO_JPEG_BYTES_SAVED
|
return if filesize < MIN_CONVERT_TO_JPEG_BYTES_SAVED
|
||||||
|
|
||||||
jpeg_tempfile = Tempfile.new(["image", ".jpg"])
|
jpeg_tempfile = Tempfile.new(["image", ".jpg"])
|
||||||
|
|
|
@ -119,7 +119,6 @@ RSpec.describe UploadCreator do
|
||||||
# pngquant will lose some colors causing some extra size reduction
|
# pngquant will lose some colors causing some extra size reduction
|
||||||
expect(thumbnail_size).to be < 7500
|
expect(thumbnail_size).to be < 7500
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'converting to jpeg' do
|
describe 'converting to jpeg' do
|
||||||
|
@ -148,7 +147,6 @@ RSpec.describe UploadCreator do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not store file as jpeg if it does not meet absolute byte saving requirements' do
|
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
|
# 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
|
# the absolute savings required of 25_000 bytes, if you save less than that
|
||||||
# skip this
|
# skip this
|
||||||
|
@ -165,7 +163,6 @@ RSpec.describe UploadCreator do
|
||||||
expect(upload.extension).to eq('png')
|
expect(upload.extension).to eq('png')
|
||||||
expect(File.extname(upload.url)).to eq('.png')
|
expect(File.extname(upload.url)).to eq('.png')
|
||||||
expect(upload.original_filename).to eq('logo.png')
|
expect(upload.original_filename).to eq('logo.png')
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should store the upload with the right extension' do
|
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')
|
expect(upload.original_filename).to eq('should_be_jpeg.jpg')
|
||||||
end
|
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
|
context "jpeg image quality settings" do
|
||||||
before do
|
before do
|
||||||
SiteSetting.png_to_jpg_quality = 75
|
SiteSetting.png_to_jpg_quality = 75
|
||||||
|
@ -229,7 +234,6 @@ RSpec.describe UploadCreator do
|
||||||
expect(File.extname(upload.url)).to eq('.png')
|
expect(File.extname(upload.url)).to eq('.png')
|
||||||
expect(upload.original_filename).to eq('large_and_unoptimized.png')
|
expect(upload.original_filename).to eq('large_and_unoptimized.png')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not convert animated WEBP images' do
|
it 'should not convert animated WEBP images' do
|
||||||
|
|
Loading…
Reference in New Issue