diff --git a/.travis.yml b/.travis.yml index 7c6f0047..0a80a242 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ rvm: script: bundle exec rspec before_install: - sudo apt-get update -qq - - sudo apt-get install -qq advancecomp gifsicle jhead jpegoptim libjpeg-progs optipng pngcrush + - sudo apt-get install -qq advancecomp gifsicle jhead jpegoptim libjpeg-progs optipng pngcrush zopfli - wget http://static.jonof.id.au/dl/kenutils/pngout-20130221-linux.tar.gz - tar -xzf pngout-*-linux.tar.gz - mv pngout-*-linux pngout-linux diff --git a/README.markdown b/README.markdown index 53ee5475..ccaae464 100644 --- a/README.markdown +++ b/README.markdown @@ -10,6 +10,7 @@ Optimize (lossless compress) images (jpeg, png, gif) using external utilities: * [optipng](http://optipng.sourceforge.net/) * [pngcrush](http://pmt.sourceforge.net/pngcrush/) * [pngout](http://www.advsys.net/ken/util/pngout.htm) +* [zopfli](https://code.google.com/p/zopfli/) Based on [ImageOptim.app](http://imageoptim.com/). diff --git a/lib/image_optim.rb b/lib/image_optim.rb index 3a058683..3c7e8c6e 100644 --- a/lib/image_optim.rb +++ b/lib/image_optim.rb @@ -247,7 +247,7 @@ def processor_count end %w[ - pngcrush pngout optipng advpng + pngcrush pngout optipng advpng zopfli jhead jpegoptim jpegtran gifsicle ].each do |worker| diff --git a/lib/image_optim/worker/zopfli.rb b/lib/image_optim/worker/zopfli.rb new file mode 100644 index 00000000..30587cc4 --- /dev/null +++ b/lib/image_optim/worker/zopfli.rb @@ -0,0 +1,22 @@ +require 'image_optim/worker' + +class ImageOptim + class Worker + class Zopfli < Worker + def image_formats + [:png] + end + + option(:splitlast, false, 'Do block splitting last instead of first'){ |v| !!v } + + option(:iterations, 15, 'Perform # iterations (default 15). More gives more compression but is slower. Examples: 10, 50, 1000') do |v| + OptionHelpers.limit_with_range(v.to_i, 1..1000) + end + + def optimize(src, dst) + args = %W[-c #{"--splitlast" if splitlast} -i#{iterations} #{src} > #{dst}] + execute(:zopfli, *args) && optimized?(src, dst) + end + end + end +end