Sha256: 2848f05529527c1709caae05f3693b06cf734540dd9aad7b3233242c472eae86

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

require 'image_optim/worker'
require 'image_optim/option_helpers'
require 'image_optim/non_negative_integer_range'

class ImageOptim
  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|
        if allow_lossy
          min = OptionHelpers.limit_with_range(v.begin, 0..100)
          min..OptionHelpers.limit_with_range(v.end, min..100)
        else
          if v != opt_def.default
            warn "#{self.class.bin_sym} #{opt_def.name} #{v} ignored " \
                'in lossless mode'
          end
          opt_def.default
        end
      end

      SPEED_OPTION =
      option(:speed, 3, 'speed/quality trade-off: '\
          '`1` - slow, '\
          '`3` - default, '\
          '`11` - fast & rough') do |v|
        OptionHelpers.limit_with_range(v.to_i, 1..11)
      end

      # Always run first
      def run_order
        -5
      end

      def optimize(src, dst)
        args = %W[
          --quality=#{quality.begin}-#{quality.end}
          --speed=#{speed}
          --output=#{dst}
          --force
          --
          #{src}
        ]
        execute(:pngquant, *args) && optimized?(src, dst)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
image_optim-0.20.2 lib/image_optim/worker/pngquant.rb
image_optim-0.20.1 lib/image_optim/worker/pngquant.rb
image_optim-0.20.0 lib/image_optim/worker/pngquant.rb