Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding pngquant to the mix #40

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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/).

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion image_optim.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/image_optim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def apply_threading(enum)
end

%w[
pngcrush pngout optipng advpng
pngcrush pngout optipng advpng pngquant
jhead jpegoptim jpegtran
gifsicle
svgo
Expand Down
29 changes: 29 additions & 0 deletions lib/image_optim/worker/pngquant.rb
Original file line number Diff line number Diff line change
@@ -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