Class: ImageOptim::Worker::Jpegtran

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

Overview

www.ijg.org/

Uses jpegtran through jpegrescan if enabled, jpegrescan is vendored with this gem

Constant Summary collapse

COPY_CHUNKS_OPTION =
option(:copy_chunks, false, 'Copy all chunks'){ |v| !!v }
PROGRESSIVE_OPTION =
option(:progressive, true, 'Create progressive JPEG file'){ |v| !!v }
JPEGRESCAN_OPTION =
option(:jpegrescan, true, 'Use jpegtran through jpegrescan, '\
'ignore progressive option'){ |v| !!v }

Instance Method Summary collapse

Methods inherited from ImageOptim::Worker

#image_formats, #initialize, #inspect, #optimized?, #options, #resolve_used_bins!, #run_order

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


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/image_optim/worker/jpegtran.rb', line 24

def optimize(src, dst)
  if jpegrescan
    args = %W[
      #{src}
      #{dst}
    ]
    args.unshift '-s' unless copy_chunks
    resolve_bin!(:jpegtran)
    execute(:jpegrescan, *args) && optimized?(src, dst)
  else
    args = %W[
      -optimize
      -outfile #{dst}
      #{src}
    ]
    args.unshift '-copy', (copy_chunks ? 'all' : 'none')
    args.unshift '-progressive' if progressive
    execute(:jpegtran, *args) && optimized?(src, dst)
  end
end

#used_binsObject


20
21
22
# File 'lib/image_optim/worker/jpegtran.rb', line 20

def used_bins
  jpegrescan ? [:jpegtran, :jpegrescan] : [:jpegtran]
end