Class: ImageOptim::Worker::Jpegrecompress

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

Overview

Constant Summary collapse

ALLOW_LOSSY_OPTION =
option(:allow_lossy, false, 'Allow worker, it is always lossy'){ |v| !!v }
QUALITY_NAMES =
[:low, :medium, :high, :veryhigh].freeze
QUALITY_OPTION =
option(:quality, 3, "JPEG quality preset: #{quality_names_desc}") do |v|
  OptionHelpers.limit_with_range(v.to_i, 0...QUALITY_NAMES.length)
end

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ImageOptim::Worker

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

Class Method Details

.init(image_optim, options = {}) ⇒ Object

Initialize only if allow_lossy


12
13
14
# File 'lib/image_optim/worker/jpegrecompress.rb', line 12

def self.init(image_optim, options = {})
  super if options[:allow_lossy]
end

Instance Method Details

#optimize(src, dst) ⇒ Object


36
37
38
39
40
41
42
43
44
# File 'lib/image_optim/worker/jpegrecompress.rb', line 36

def optimize(src, dst)
  args = %W[
    --quality #{QUALITY_NAMES[quality]}
    --no-copy
    #{src}
    #{dst}
  ]
  execute(:'jpeg-recompress', *args) && optimized?(src, dst)
end

#run_orderObject

Run early as lossy worker


32
33
34
# File 'lib/image_optim/worker/jpegrecompress.rb', line 32

def run_order
  -5
end

#used_binsObject


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

def used_bins
  [:'jpeg-recompress']
end