mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:21:18 +08:00
FEATURE: do not switch to JPEG unless you meet 75k byte savings
This also adjusts the algorithm to expect - 30% saving for JPEG conversion AND - Minimum of 75K bytes saved The reasoning for increase of saving requirements is cause PNG may have been uploaded unoptimized, 30% saving on PNG is very possible
This commit is contained in:
@ -99,13 +99,37 @@ RSpec.describe UploadCreator do
|
||||
end
|
||||
|
||||
describe 'converting to jpeg' do
|
||||
let(:filename) { "logo.png" }
|
||||
let(:filename) { "should_be_jpeg.png" }
|
||||
let(:file) { file_from_fixtures(filename) }
|
||||
|
||||
let(:small_filename) { "logo.png" }
|
||||
let(:small_file) { file_from_fixtures(small_filename) }
|
||||
|
||||
before do
|
||||
SiteSetting.png_to_jpg_quality = 1
|
||||
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
|
||||
|
||||
expect do
|
||||
UploadCreator.new(small_file, small_filename,
|
||||
pasted: true,
|
||||
force_optimize: true
|
||||
).create_for(user.id)
|
||||
end.to change { Upload.count }.by(1)
|
||||
|
||||
upload = Upload.last
|
||||
|
||||
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
|
||||
expect do
|
||||
UploadCreator.new(file, filename,
|
||||
@ -118,7 +142,7 @@ RSpec.describe UploadCreator do
|
||||
|
||||
expect(upload.extension).to eq('jpeg')
|
||||
expect(File.extname(upload.url)).to eq('.jpeg')
|
||||
expect(upload.original_filename).to eq('logo.jpg')
|
||||
expect(upload.original_filename).to eq('should_be_jpeg.jpg')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user