Sha256: c4bda9319868df5181688e250d5567faa21cf085eea313ff6174f30a8e8bd790

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

require 'image_optim/worker'
require 'image_optim/option_helpers'

class ImageOptim
  class Worker
    class Jpegoptim < Worker
      option(:strip, :all, Array, 'List of extra markers to strip: comments, exif, iptc, icc or all') do |v|
        values = Array(v).map(&:to_s)
        known_values = %w[all comments exif iptc icc]
        unknown_values = values - known_values
        warn "Unknown markers for jpegoptim: #{unknown_values.join(', ')}" unless unknown_values.empty?
        values & known_values
      end

      option(:max_quality, 100, 'Maximum image quality factor 0..100'){ |v| OptionHelpers.limit_with_range(v.to_i, 0..100) }

      # Run first if max_quality < 100
      def run_order
        max_quality < 100 ? -1 : 0
      end

      def optimize(src, dst)
        src.copy(dst)
        args = %W[-q -- #{dst}]
        strip.each do |strip_marker|
          args.unshift "--strip-#{strip_marker}"
        end
        args.unshift "-m#{max_quality}" if max_quality < 100
        execute(:jpegoptim, *args) && optimized?(src, dst)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
image_optim-0.12.0 lib/image_optim/worker/jpegoptim.rb
image_optim-0.11.2 lib/image_optim/worker/jpegoptim.rb
image_optim-0.11.1 lib/image_optim/worker/jpegoptim.rb
image_optim-0.11.0 lib/image_optim/worker/jpegoptim.rb
image_optim-0.10.2 lib/image_optim/worker/jpegoptim.rb
image_optim-0.10.1 lib/image_optim/worker/jpegoptim.rb
image_optim-0.10.0 lib/image_optim/worker/jpegoptim.rb