Sha256: e2cbe56350597416ead3b388af8e41d3939b2e8bb3af7d9dccafbebea47a8555

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

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

class ImageOptim
  class Worker
    # http://www.advsys.net/ken/util/pngout.htm
    class Pngout < Worker
      COPY_CHUNKS_OPTION =
      option(:copy_chunks, false, 'Copy optional chunks'){ |v| !!v }

      STRATEGY_OPTION =
      option(:strategy, 0, 'Strategy: '\
                           '`0` - xtreme, '\
                           '`1` - intense, '\
                           '`2` - longest Match, '\
                           '`3` - huffman Only, '\
                           '`4` - uncompressed') do |v|
        OptionHelpers.limit_with_range(v.to_i, 0..4)
      end

      def run_order
        2
      end

      def optimize(src, dst, options = {})
        args = %W[
          -k#{copy_chunks ? 1 : 0}
          -s#{strategy}
          -q
          -y
          #{src}
          #{dst}
        ]
        execute(:pngout, args, options) && optimized?(src, dst)
      rescue SignalException => e
        raise unless Signal.list.key(e.signo) == 'SEGV'
        raise unless resolve_bin!(:pngout).version <= '20150920'

        warn "pngout caused Segmentation fault for #{src}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
image_optim-0.31.1 lib/image_optim/worker/pngout.rb
image_optim-0.31.0 lib/image_optim/worker/pngout.rb