Sha256: 635c6ca1dcb108a151639a1310a9a72e0759defe84d8b18b6034a77e5d430b5d

Contents?: true

Size: 1.41 KB

Versions: 12

Compression:

Stored size: 1.41 KB

Contents

require 'image_optim'

class ImageOptim
  class Jpegoptim < Worker
    # Strip Comment markers from output file (defaults to true)
    attr_reader :strip_comments

    # Strip Exif markers from output file (defaults to true)
    attr_reader :strip_exif

    # Strip IPTC markers from output file (defaults to true)
    attr_reader :strip_iptc

    # Strip ICC profile markers from output file (defaults to true)
    attr_reader :strip_icc

    # Maximum image quality factor (defaults to 100)
    attr_reader :max_quality

    # Run first if max_quality < 100
    def run_first?
      max_quality < 100
    end

  private

    def parse_options(options)
      get_option!(options, :strip_comments, true){ |v| !!v }
      get_option!(options, :strip_exif, true){ |v| !!v }
      get_option!(options, :strip_iptc, true){ |v| !!v }
      get_option!(options, :strip_icc, true){ |v| !!v }
      get_option!(options, :max_quality, 100){ |v| v.to_i }
    end

    def command_args(src, dst)
      src.copy(dst)
      args = %W[-q -- #{dst}]
      if strip_comments && strip_exif && strip_iptc && strip_icc
        args.unshift '--strip-all'
      else
        args.unshift '--strip-com' if strip_comments
        args.unshift '--strip-exif' if strip_exif
        args.unshift '--strip-iptc' if strip_iptc
        args.unshift '--strip-icc' if strip_icc
      end
      args.unshift "-m#{max_quality}" if max_quality < 100
      args
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
image_optim-0.6.0 lib/image_optim/workers/jpegoptim.rb
image_optim-0.5.1 lib/image_optim/workers/jpegoptim.rb
image_optim-0.5.0 lib/image_optim/workers/jpegoptim.rb
image_optim-0.4.2 lib/image_optim/workers/jpegoptim.rb
image_optim-0.4.1 lib/image_optim/workers/jpegoptim.rb
image_optim-0.4.0 lib/image_optim/workers/jpegoptim.rb
image_optim-0.3.2 lib/image_optim/workers/jpegoptim.rb
image_optim-0.3.1 lib/image_optim/workers/jpegoptim.rb
image_optim-0.3.0 lib/image_optim/workers/jpegoptim.rb
image_optim-0.2.1 lib/image_optim/workers/jpegoptim.rb
image_optim-0.2.0 lib/image_optim/workers/jpegoptim.rb
image_optim-0.1.0 lib/image_optim/workers/jpegoptim.rb