Class: ImageOptim::Worker::Pngcrush

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

Overview

Constant Summary collapse

CHUNKS_OPTION =
option(:chunks, :alla, Array, 'List of chunks to remove or ' \
                              '`:alla` - all except tRNS/transparency or ' \
                              '`:allb` - all except tRNS and gAMA/gamma') do |v|
  Array(v).map(&:to_s)
end
FIX_OPTION =
option(:fix, false, 'Fix otherwise fatal conditions ' \
'such as bad CRCs'){ |v| !!v }
BRUTE_OPTION =
option(:brute, false, 'Brute force try all methods, ' \
'very time-consuming and generally not worthwhile'){ |v| !!v }
BLACKEN_OPTION =
option(:blacken, true, 'Blacken fully transparent pixels'){ |v| !!v }

Instance Method Summary collapse

Methods inherited from ImageOptim::Worker

#image_formats, #initialize, #inspect, #optimized?, #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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/image_optim/worker/pngcrush.rb', line 31

def optimize(src, dst, options = {})
  flags = %w[
    -reduce
    -cc
    -q
  ]
  chunks.each do |chunk|
    flags.push '-rem', chunk
  end
  flags.push '-fix' if fix
  flags.push '-brute' if brute
  if blacken && resolve_bin!(:pngcrush).version >= '1.7.38'
    flags.push '-blacken'
  end

  args = flags + %W[
    --
    #{src}
    #{dst}
  ]

  execute(:pngcrush, args, options) && optimized?(src, dst)
end

#run_orderObject



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

def run_order
  -6
end