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

Zopfli worker #18

Closed
wants to merge 5 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 @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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/).

Expand Down
2 changes: 1 addition & 1 deletion lib/image_optim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
22 changes: 22 additions & 0 deletions lib/image_optim/worker/zopfli.rb
Original file line number Diff line number Diff line change
@@ -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