Sha256: 29119a6cdc128090e7b9776cd7763bcefbea0edb7cb2df29a32cc28d5a9f388b

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require 'image_optim/worker'

class ImageOptim
  class Worker
    # http://www.ijg.org/
    #
    # Uses jpegtran through jpegrescan if enabled, jpegrescan is vendored with
    # this gem
    class Jpegtran < Worker
      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, false, 'Use jpegtran through jpegrescan, '\
          'ignore progressive option'){ |v| !!v }

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

      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
image_optim-0.17.1 lib/image_optim/worker/jpegtran.rb
image_optim-0.17.0 lib/image_optim/worker/jpegtran.rb
image_optim-0.16.0 lib/image_optim/worker/jpegtran.rb