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) ⇒ Object


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

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

#optimized?(src, dst) ⇒ Boolean

Returns:

  • (Boolean)

46
47
48
# File 'lib/image_optim/worker/optipng.rb', line 46

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

#run_orderObject


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

def run_order
  -4
end