Sha256: 55170f78e17828e91e12d34a74cb8b71e0335bd581fc4f87d9f881966ff119d5

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

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

class ImageOptim
  class Worker
    # http://optipng.sourceforge.net/
    class Optipng < Worker
      LEVEL_OPTION =
      option(:level, 6, 'Optimization level preset: '\
          '`0` is least, '\
          '`7` is best') do |v|
        OptionHelpers.limit_with_range(v.to_i, 0..7)
      end

      INTERLACE_OPTION =
      option(:interlace, false, TrueFalseNil, 'Interlace: '\
          '`true` - interlace on, '\
          '`false` - interlace off, '\
          '`nil` - as is in original image') do |v|
        TrueFalseNil.convert(v)
      end

      STRIP_OPTION =
      option(:strip, true, 'Remove all auxiliary chunks'){ |v| !!v }

      def run_order
        -4
      end

      def optimize(src, dst)
        src.copy(dst)
        args = %W[
          -o #{level}
          -quiet
          --
          #{dst}
        ]
        args.unshift "-i#{interlace ? 1 : 0}" unless interlace.nil?
        args.unshift '-strip', 'all' if strip
        execute(:optipng, *args) && optimized?(src, dst)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
openstreetmap-image_optim-0.21.0.1 lib/image_optim/worker/optipng.rb
image_optim-0.21.0 lib/image_optim/worker/optipng.rb