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|
  TrueFalseNil.convert(v)
end
STRIP_OPTION =
option(:strip, true, 'Remove all auxiliary chunks'){ |v| !!v }

Instance Method Summary collapse

Methods inherited from ImageOptim::Worker

#image_formats, #initialize, #inspect, #options, #resolve_used_bins!, #used_bins

Methods included from ClassMethods

#bin_sym, #create_all, #create_all_by_format, extended, #inherited, #klasses, #option, #option_definitions

Constructor Details

This class inherits a constructor from ImageOptim::Worker

Instance Method Details

#optimize(src, dst, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/image_optim/worker/optipng.rb', line 33

def optimize(src, dst, options = {})
  src.copy(dst)
  args = %W[
    -o #{level}
    -quiet
    --
    #{dst}
  ]
  args.unshift "-i#{interlace ? 1 : 0}" unless interlace.nil?
  if strip && resolve_bin!(:optipng).version >= '0.7'
    args.unshift '-strip', 'all'
  end
  execute(:optipng, args, options) && optimized?(src, dst)
end

#optimized?(src, dst) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/image_optim/worker/optipng.rb', line 48

def optimized?(src, dst)
  interlace ? dst.size? : super
end

#run_orderObject



29
30
31
# File 'lib/image_optim/worker/optipng.rb', line 29

def run_order
  -4
end