diff --git a/.travis.yml b/.travis.yml index 28816f20..55f7792c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,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 pngquant - 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 eb1a98fb..4100420e 100644 --- a/README.markdown +++ b/README.markdown @@ -11,6 +11,7 @@ Optimize (lossless compress) images (jpeg, png, gif, svg) using external utiliti * [pngcrush](http://pmt.sourceforge.net/pngcrush/) * [pngout](http://www.advsys.net/ken/util/pngout.htm) * [svgo](https://github.com/svg/svgo) +* [pngquant](http://pngquant.org/) Based on [ImageOptim.app](http://imageoptim.com/). @@ -107,7 +108,7 @@ make && cp -f pngcrush /usr/local/bin ### OS X: Macports ```bash -sudo port install advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush +sudo port install advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush pngquant ``` ### OS X: Brew diff --git a/image_optim.gemspec b/image_optim.gemspec index ff4fc1c4..a8e285ab 100644 --- a/image_optim.gemspec +++ b/image_optim.gemspec @@ -3,7 +3,7 @@ Gem::Specification.new do |s| s.name = 'image_optim' s.version = '0.12.0' - s.summary = %q{Optimize (lossless compress) images (jpeg, png, gif, svg) using external utilities (advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout, svgo)} + s.summary = %q{Optimize (lossless compress) images (jpeg, png, gif, svg) using external utilities (advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout, svgo, pngquant)} s.homepage = "http://github.com/toy/#{s.name}" s.authors = ['Ivan Kuchin'] s.license = 'MIT' diff --git a/lib/image_optim.rb b/lib/image_optim.rb index 58923ebd..8b225c2c 100644 --- a/lib/image_optim.rb +++ b/lib/image_optim.rb @@ -184,7 +184,7 @@ def apply_threading(enum) end %w[ - pngcrush pngout optipng advpng + pngcrush pngout optipng advpng pngquant jhead jpegoptim jpegtran gifsicle svgo diff --git a/lib/image_optim/worker/pngquant.rb b/lib/image_optim/worker/pngquant.rb new file mode 100644 index 00000000..fbc4452a --- /dev/null +++ b/lib/image_optim/worker/pngquant.rb @@ -0,0 +1,29 @@ +require 'image_optim/worker' +require 'image_optim/option_helpers' + +class ImageOptim + class Worker + class Pngquant < Worker + option(:quality, 80 , "don't save below min, use less colors below max (0-100)") do |v| + OptionHelpers.limit_with_range(v.to_i, 0..100) + end + + option(:speed, 1 , 'speed/quality trade-off. 1=slow, 3=default, 11=fast & rough') do |v| + OptionHelpers.limit_with_range(v.to_i, 1..11) + end + + # Always run first + def run_order + -1 + end + + def optimize(src, dst) + args = %W[--quality=#{quality} --speed=#{speed} --ext=-min.png #{src}] + mv_args = %W[#{src}-min.png #{dst}] + execute(:pngquant, *args) && + execute(:mv, *mv_args) && + optimized?(src, dst) + end + end + end +end