<commit_before>require 'image_optim/worker'

class ImageOptim
  class Worker
    # http://www.lcdf.org/gifsicle/
    class Gifsicle < Worker
      INTERLACE_OPTION =
      option(:interlace, false, 'Turn interlacing on'){ |v| !!v }

      def optimize(src, dst)
        args = %W[
          -o #{dst}
          -O3
          --no-comments
          --no-names
          --same-delay
          --same-loopcount
          --no-warnings
          --
          #{src}
        ]
        args.unshift('-i') if interlace
        execute(:gifsicle, *args) && optimized?(src, dst)
      end
    end
  end
end<commit_msg>Adds a level option to gifsicle<commit_after>require 'image_optim/worker'

class ImageOptim
  class Worker
    # http://www.lcdf.org/gifsicle/
    class Gifsicle < Worker
      INTERLACE_OPTION =
      option(:interlace, false, 'Turn interlacing on'){ |v| !!v }

      LEVEL_OPTION =
      option(:level, 3, 'Compression level: '\
          '`0` - Does nothing, '\
          '`1` - stores only the changed portion of each image, '\
          '`2` - slso uses transparency to shrink the file further., '\
          '`3` - try several optimization methods (usually slower, sometimes better results)') do |v|
        OptionHelpers.limit_with_range(v.to_i, 0..3)
      end

      def optimize(src, dst)
        args = %W[
          -o #{dst}
          --no-comments
          --no-names
          --same-delay
          --same-loopcount
          --no-warnings
          --careful
          --
          #{src}
        ]
        args.unshift('-i') if interlace
        args.unshift("-O#{level}") unless level == 0
        execute(:gifsicle, *args) && optimized?(src, dst)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1271981242672919, 'fraction_numerical': 0.005275498241500586, 'mean_word_length': 1.6839622641509433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4872510', 'n_tokens_mistral': 549, 'n_tokens_neox': 542, 'n_words': 135}