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

Add svgo worker for optimizing SVG #30

Merged
merged 4 commits into from
Feb 16, 2014
Merged
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
11 changes: 10 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# image_optim

Optimize (lossless compress) images (jpeg, png, gif) using external utilities:
Optimize (lossless compress) images (jpeg, png, gif, svg) using external utilities:

* [advpng](http://advancemame.sourceforge.net/doc-advpng.html) from [AdvanceCOMP](http://advancemame.sourceforge.net/comp-readme.html)
* [gifsicle](http://www.lcdf.org/gifsicle/)
Expand All @@ -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)
* [svgo](https://github.com/svg/svgo)

Based on [ImageOptim.app](http://imageoptim.com/).

Expand Down Expand Up @@ -90,6 +91,14 @@ You can install `pngout` by downloading and installing the [binary versions](htt

_Note: pngout is free to use even in commercial soft, but you can not redistribute, repackage or reuse it without consent and agreement of creator. [license](http://advsys.net/ken/utils.htm#pngoutkziplicense)_

### svgo installation (optional)

svgo is available from NPM.

~~~bash
npm install -g svgo
~~~

## Usage

### From shell
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.10.2'
s.summary = %q{Optimize (lossless compress) images (jpeg, png, gif) using external utilities (advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout)}
s.summary = %q{Optimize (lossless compress) images (jpeg, png, gif, svg) using external utilities (advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout, svgo)}
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 @@ -181,7 +181,7 @@ def apply_threading(enum)
%w[
pngcrush pngout optipng advpng
jhead jpegoptim jpegtran
gifsicle
gifsicle svgo
].each do |worker|
require "image_optim/worker/#{worker}"
end
Expand Down
1 change: 1 addition & 0 deletions lib/image_optim/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Railtie < Rails::Railtie
app.assets.register_preprocessor 'image/gif', :image_optim, &processor
app.assets.register_preprocessor 'image/jpeg', :image_optim, &processor
app.assets.register_preprocessor 'image/png', :image_optim, &processor
app.assets.register_preprocessor 'image/svg+xml', :image_optim, &processor
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/image_optim/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def initialize(image_optim, options = {})

# List of formats which worker can optimize
def image_formats
format_from_name = self.class.name.downcase[/gif|jpeg|png/]
format_from_name = self.class.name.downcase[/gif|jpeg|png|svg/]
raise "#{self.class}: can't guess applicable format from worker name" unless format_from_name
[format_from_name.to_sym]
end
Expand Down
12 changes: 12 additions & 0 deletions lib/image_optim/worker/svgo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'image_optim/worker'

class ImageOptim
class Worker
class Svgo < Worker
def optimize(src, dst)
args = %W[-i #{src} -o #{dst}]
execute(:svgo, *args) && optimized?(src, dst)
end
end
end
end