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
METHOD_OPTION =
option(:method, 'ssim', 'Comparison Metric: ' \
                        '`mpe` - Mean pixel error, ' \
                        '`ssim` - Structural similarity, ' \
                        '`ms-ssim` - Multi-scale structural similarity (slow!), ' \
                        '`smallfry` - Linear-weighted BBCQ-like (may be patented)') do |v, opt_def|
  if %w[mpe ssim ms-ssim smallfry].include? v
    v
  else
    warn "Unknown method for jpegrecompress: #{v}"
    opt_def.default
  end
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



14
15
16
# File 'lib/image_optim/worker/jpegrecompress.rb', line 14

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

Instance Method Details

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



52
53
54
55
56
57
58
59
60
61
# File 'lib/image_optim/worker/jpegrecompress.rb', line 52

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

#run_orderObject

Run early as lossy worker



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

def run_order
  -5
end

#used_binsObject



43
44
45
# File 'lib/image_optim/worker/jpegrecompress.rb', line 43

def used_bins
  [:'jpeg-recompress']
end