Class: ImageOptim::Worker::Optipng

Inherits:
ImageOptim::Worker show all
Defined in:
lib/image_optim/worker/optipng.rb

Overview

Constant Summary collapse

LEVEL_OPTION =
option(:level, 6, 'Optimization level preset: '\
    '`0` is least, '\
    '`7` is best') do |v|
  OptionHelpers.limit_with_range(v.to_i, 0..7)
end
INTERLACE_OPTION =
option(:interlace, false, TrueFalseNil, 'Interlace, '\
    '`true` - interlace on, '\
    '`false` - interlace off, '\
    '`nil` - as is in original image') do |v|
  # convert everything truthy to `true`, leave `false` and `nil` as is
  v && true
end

Instance Method Summary collapse

Methods inherited from ImageOptim::Worker

#<=>, bin_sym, #image_formats, inherited, #initialize, klasses, #optimized?, option, option_definitions, #run_order

Constructor Details

This class inherits a constructor from ImageOptim::Worker

Instance Method Details

#optimize(src, dst) ⇒ Object



25
26
27
28
29
30
# File 'lib/image_optim/worker/optipng.rb', line 25

def optimize(src, dst)
  src.copy(dst)
  args = %W[-o#{level} -quiet -- #{dst}]
  args.unshift "-i#{interlace ? 1 : 0}" unless interlace.nil?
  execute(:optipng, *args) && optimized?(src, dst)
end