Sha256: b462d3c10c3d6ee6f70ee36656de7482bd078ec7f90df36dc8fa9ae9c5b60bb1

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

require 'image_optim/worker'

class ImageOptim
  class Worker
    # http://pmt.sourceforge.net/pngcrush/
    class Pngcrush < Worker
      CHUNKS_OPTION =
      option(:chunks, :alla, Array, 'List of chunks to remove or '\
          '`:alla` - all except tRNS/transparency or '\
          '`:allb` - all except tRNS and gAMA/gamma') do |v|
        Array(v).map(&:to_s)
      end

      FIX_OPTION =
      option(:fix, false, 'Fix otherwise fatal conditions '\
          'such as bad CRCs'){ |v| !!v }

      BRUTE_OPTION =
      option(:brute, false, 'Brute force try all methods, '\
          'very time-consuming and generally not worthwhile'){ |v| !!v }

      # Always run first [-1]
      def run_order
        -1
      end

      def optimize(src, dst)
        args = %W[-reduce -cc -q -- #{src} #{dst}]
        chunks.each do |chunk|
          args.unshift '-rem', chunk
        end
        args.unshift '-fix' if fix
        args.unshift '-brute' if brute
        execute(:pngcrush, *args) && optimized?(src, dst)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
image_optim-0.17.1 lib/image_optim/worker/pngcrush.rb
image_optim-0.17.0 lib/image_optim/worker/pngcrush.rb
image_optim-0.16.0 lib/image_optim/worker/pngcrush.rb
image_optim-0.15.0 lib/image_optim/worker/pngcrush.rb
image_optim-0.14.0 lib/image_optim/worker/pngcrush.rb