mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: introduce lossy color optimization on resized pngs
This feature ensures optimized images run via pngquant, this results extreme amounts of savings for resized images. Effectively the only impact is that the color palette on small resized images is reduced to 256. To ensure safety we only apply this optimisation to images smaller than 500k. This commit also makes a bunch of image specs less fragile.
This commit is contained in:
@ -6,7 +6,7 @@ describe OptimizedImage do
|
||||
|
||||
unless ENV["TRAVIS"]
|
||||
describe '.crop' do
|
||||
it 'should work correctly (requires correct version of image optim)' do
|
||||
it 'should produce cropped images' do
|
||||
tmp_path = "/tmp/cropped.png"
|
||||
|
||||
begin
|
||||
@ -17,12 +17,15 @@ describe OptimizedImage do
|
||||
5
|
||||
)
|
||||
|
||||
fixture_path = "#{Rails.root}/spec/fixtures/images/cropped.png"
|
||||
fixture_hex = Digest::MD5.hexdigest(File.read(fixture_path))
|
||||
# we don't want to deal with something new here every time image magick
|
||||
# is upgraded or pngquant is upgraded, lets just test the basics ...
|
||||
# cropped image should be less than 120 bytes
|
||||
|
||||
cropped_hex = Digest::MD5.hexdigest(File.read(tmp_path))
|
||||
cropped_size = File.size(tmp_path)
|
||||
|
||||
expect(cropped_size).to be < 120
|
||||
expect(cropped_size).to be > 50
|
||||
|
||||
expect(cropped_hex).to eq(fixture_hex)
|
||||
ensure
|
||||
File.delete(tmp_path) if File.exists?(tmp_path)
|
||||
end
|
||||
@ -128,7 +131,7 @@ describe OptimizedImage do
|
||||
end
|
||||
|
||||
describe '.downsize' do
|
||||
it 'should work correctly (requires correct version of image optim)' do
|
||||
it 'should downsize logo' do
|
||||
tmp_path = "/tmp/downsized.png"
|
||||
|
||||
begin
|
||||
@ -138,12 +141,10 @@ describe OptimizedImage do
|
||||
"100x100\>"
|
||||
)
|
||||
|
||||
fixture_path = "#{Rails.root}/spec/fixtures/images/downsized.png"
|
||||
fixture_hex = Digest::MD5.hexdigest(File.read(fixture_path))
|
||||
info = FastImage.new(tmp_path)
|
||||
expect(info.size).to eq([100, 27])
|
||||
expect(File.size(tmp_path)).to be < 2300
|
||||
|
||||
downsized_hex = Digest::MD5.hexdigest(File.read(tmp_path))
|
||||
|
||||
expect(downsized_hex).to eq(fixture_hex)
|
||||
ensure
|
||||
File.delete(tmp_path) if File.exists?(tmp_path)
|
||||
end
|
||||
|
Reference in New Issue
Block a user