diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 84a07fda..f706c693 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -2,6 +2,8 @@ ## unreleased +* Use quality `0..100` by default in lossy mode of pngquant worker [#77](https://github.com/toy/image_optim/issues/77) [@toy](https://github.com/toy) + ## v0.21.0 (2015-05-30) * Use exifr 1.2.2 with fix for a bug [#85](https://github.com/toy/image_optim/issues/85) [@toy](https://github.com/toy) diff --git a/lib/image_optim/worker/pngquant.rb b/lib/image_optim/worker/pngquant.rb index 2eee01a0..202deaa0 100644 --- a/lib/image_optim/worker/pngquant.rb +++ b/lib/image_optim/worker/pngquant.rb @@ -7,19 +7,24 @@ class Worker # http://pngquant.org/ class Pngquant < Worker QUALITY_OPTION = - option(:quality, 100..100, NonNegativeIntegerRange, 'min..max - don\'t '\ - 'save below min, use less colors below max (both in range `0..100`; '\ - 'in yaml - `!ruby/range 0..100`), ignored in default/lossless '\ - 'mode') do |v, opt_def| + option(:quality, '100..100, 0..100 in lossy mode', + NonNegativeIntegerRange, 'min..max - don\'t '\ + 'save below min, use less colors below max (both in range `0..100`; '\ + 'in yaml - `!ruby/range 0..100`), ignored in default/lossless '\ + 'mode') do |v, opt_def| if allow_lossy - min = OptionHelpers.limit_with_range(v.begin, 0..100) - min..OptionHelpers.limit_with_range(v.end, min..100) + if v == opt_def.default + 0..100 + else + min = OptionHelpers.limit_with_range(v.begin, 0..100) + min..OptionHelpers.limit_with_range(v.end, min..100) + end else if v != opt_def.default warn "#{self.class.bin_sym} #{opt_def.name} #{v} ignored " \ 'in lossless mode' end - opt_def.default + 100..100 end end diff --git a/spec/image_optim/worker/pngquant_spec.rb b/spec/image_optim/worker/pngquant_spec.rb new file mode 100644 index 00000000..894f0c88 --- /dev/null +++ b/spec/image_optim/worker/pngquant_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' +require 'image_optim/worker/pngquant' + +describe ImageOptim::Worker::Pngquant do + describe 'quality option' do + describe 'default' do + subject{ described_class::QUALITY_OPTION.default } + + it{ is_expected.to match(/100\.\.100.*0\.\.100/) } + end + + describe 'value' do + let(:options){ {} } + subject{ described_class.new(ImageOptim.new, options).quality } + + context 'by default' do + it{ is_expected.to eq(100..100) } + end + + context 'when lossy allowed by default' do + let(:options){ {:allow_lossy => true} } + + it{ is_expected.to eq(0..100) } + end + end + end +end diff --git a/spec/image_optim_spec.rb b/spec/image_optim_spec.rb index 3eebd081..e8466d43 100644 --- a/spec/image_optim_spec.rb +++ b/spec/image_optim_spec.rb @@ -67,7 +67,7 @@ def temp_copy(image) base_options = {:skip_missing_workers => false} [ ['lossless', base_options, 0], - ['lossy', base_options.merge(:allow_lossy => true), 0.01], + ['lossy', base_options.merge(:allow_lossy => true), 0.025], ].each do |type, options, max_difference| image_optim = ImageOptim.new(options) describe type do