image_optim 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +1 -0
- data/README.markdown +72 -35
- data/image_optim.gemspec +3 -3
- data/lib/image_optim/handler.rb +8 -0
- data/lib/image_optim/image_path.rb +1 -0
- data/lib/image_optim/railtie.rb +6 -1
- data/lib/image_optim/worker/svgo.rb +12 -0
- data/lib/image_optim/worker.rb +1 -1
- data/lib/image_optim.rb +2 -0
- data/spec/image_optim/handler_spec.rb +4 -0
- data/spec/images/test.svg +3 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWIyNWIzNTYyNmNhOGViOTE3NWU0NmFiMGYyYjk3NTM3ZDNkYzJhMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Mjg0NmZlYTAzYmQyYTQyMDBhNjA0ZTg0MjVlYWIwNTE1MTJiYmE5MQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2QzMDBmZTAwNjY4OGIyNGMwZGNkMmQyZTMyODM3ZTc0NzY3YTE5Y2I4Mzcx
|
10
|
+
MmZhZDBjYzc4ZGU4MDE5MTI2YzNiOTgyNTU1NGE0Mzg3NDUzOWNkNGFlM2Jj
|
11
|
+
OTY4MGM5NGIxYWRiYjQxNmNiOWI0ZDllY2E3YjUwZjMyNGZmZGM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmRjNmMwMDllZDk1ZjFkN2I5NTk1Nzc4ODhlZjFiMWZjMjBiNmQzOTBmZDYy
|
14
|
+
MmEzZTFmNWViYTg2NDAzOTM4ZjU0NTViZTJmYWU5MjI4MDcwYjc3ZDY2ZmE5
|
15
|
+
YzM5MGE3ZDVmMzA5OTg0NzI4Y2FjNmU0OWZkM2FjNTIxOWNjNDc=
|
data/.travis.yml
CHANGED
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# image_optim
|
2
2
|
|
3
|
-
Optimize (lossless compress) images (jpeg, png, gif) using external utilities:
|
3
|
+
Optimize (lossless compress) images (jpeg, png, gif, svg) using external utilities:
|
4
4
|
|
5
5
|
* [advpng](http://advancemame.sourceforge.net/doc-advpng.html) from [AdvanceCOMP](http://advancemame.sourceforge.net/comp-readme.html)
|
6
6
|
* [gifsicle](http://www.lcdf.org/gifsicle/)
|
@@ -10,6 +10,7 @@ Optimize (lossless compress) images (jpeg, png, gif) using external utilities:
|
|
10
10
|
* [optipng](http://optipng.sourceforge.net/)
|
11
11
|
* [pngcrush](http://pmt.sourceforge.net/pngcrush/)
|
12
12
|
* [pngout](http://www.advsys.net/ken/util/pngout.htm)
|
13
|
+
* [svgo](https://github.com/svg/svgo)
|
13
14
|
|
14
15
|
Based on [ImageOptim.app](http://imageoptim.com/).
|
15
16
|
|
@@ -20,7 +21,9 @@ Based on [ImageOptim.app](http://imageoptim.com/).
|
|
20
21
|
|
21
22
|
## Gem installation
|
22
23
|
|
23
|
-
|
24
|
+
```sh
|
25
|
+
gem install image_optim
|
26
|
+
```
|
24
27
|
|
25
28
|
## Binaries location
|
26
29
|
|
@@ -52,37 +55,49 @@ Besides permanently setting environment variables in `~/.profile`, `~/.bash_prof
|
|
52
55
|
|
53
56
|
### Linux - Debian/Ubuntu
|
54
57
|
|
55
|
-
|
58
|
+
```bash
|
59
|
+
sudo apt-get install -y advancecomp gifsicle jhead jpegoptim libjpeg-progs optipng pngcrush
|
60
|
+
```
|
56
61
|
|
57
62
|
### Linux - RHEL/Fedora/Centos
|
58
63
|
|
59
|
-
|
64
|
+
```bash
|
65
|
+
sudo yum install -y advancecomp gifsicle jhead libjpeg optipng
|
66
|
+
```
|
60
67
|
|
61
68
|
You will also need to install `jpegoptim` and `pngcrush` from source:
|
62
69
|
|
63
70
|
#### jpegoptim
|
64
71
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
72
|
+
```bash
|
73
|
+
cd /tmp
|
74
|
+
curl -O http://www.kokkonen.net/tjko/src/jpegoptim-1.3.0.tar.gz
|
75
|
+
tar zxf jpegoptim-1.3.0.tar.gz
|
76
|
+
cd jpegoptim-1.3.0
|
77
|
+
./configure && make && make install
|
78
|
+
```
|
70
79
|
|
71
80
|
#### pngcrush
|
72
81
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
82
|
+
```bash
|
83
|
+
cd /tmp
|
84
|
+
curl -O http://iweb.dl.sourceforge.net/project/pmt/pngcrush/1.7.70/pngcrush-1.7.70.tar.gz
|
85
|
+
tar zxf pngcrush-1.7.70.tar.gz
|
86
|
+
cd pngcrush-1.7.70
|
87
|
+
make && cp -f pngcrush /usr/local/bin
|
88
|
+
```
|
78
89
|
|
79
90
|
### OS X: Macports
|
80
91
|
|
81
|
-
|
92
|
+
```bash
|
93
|
+
sudo port install advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush
|
94
|
+
```
|
82
95
|
|
83
96
|
### OS X: Brew
|
84
97
|
|
85
|
-
|
98
|
+
```bash
|
99
|
+
brew install advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush
|
100
|
+
```
|
86
101
|
|
87
102
|
### pngout installation (optional)
|
88
103
|
|
@@ -90,47 +105,67 @@ You can install `pngout` by downloading and installing the [binary versions](htt
|
|
90
105
|
|
91
106
|
_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)_
|
92
107
|
|
108
|
+
### svgo installation (optional)
|
109
|
+
|
110
|
+
`svgo` is available from NPM.
|
111
|
+
|
112
|
+
```bash
|
113
|
+
npm install -g svgo
|
114
|
+
```
|
115
|
+
|
93
116
|
## Usage
|
94
117
|
|
95
118
|
### From shell
|
96
119
|
|
97
|
-
|
120
|
+
```sh
|
121
|
+
image_optim *.{jpg,png,gif,svg}
|
98
122
|
|
99
|
-
|
123
|
+
image_optim -h
|
124
|
+
```
|
100
125
|
|
101
126
|
### From ruby
|
102
127
|
|
103
128
|
Initilize optimizer:
|
104
129
|
|
105
|
-
|
130
|
+
```ruby
|
131
|
+
image_optim = ImageOptim.new
|
106
132
|
|
107
|
-
|
133
|
+
image_optim = ImageOptim.new(:pngout => false)
|
108
134
|
|
109
|
-
|
135
|
+
image_optim = ImageOptim.new(:nice => 20)
|
136
|
+
```
|
110
137
|
|
111
138
|
Optimize image getting temp path:
|
112
139
|
|
113
|
-
|
140
|
+
```ruby
|
141
|
+
image_optim.optimize_image('a.png')
|
142
|
+
```
|
114
143
|
|
115
144
|
Optimize image in place:
|
116
145
|
|
117
|
-
|
146
|
+
```ruby
|
147
|
+
image_optim.optimize_image!('b.jpg')
|
148
|
+
```
|
118
149
|
|
119
150
|
Optimize image data:
|
120
151
|
|
121
|
-
|
152
|
+
```ruby
|
153
|
+
image_optim.optimize_image_data(data)
|
154
|
+
```
|
122
155
|
|
123
156
|
Multiple images:
|
124
157
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
158
|
+
```ruby
|
159
|
+
image_optim.optimize_images(Dir['*.png']) do |unoptimized, optimized|
|
160
|
+
if optimized
|
161
|
+
puts "#{unoptimized} => #{optimized}"
|
162
|
+
end
|
163
|
+
end
|
130
164
|
|
131
|
-
|
165
|
+
image_optim.optimize_images!(Dir['*.*'])
|
132
166
|
|
133
|
-
|
167
|
+
image_optim.optimize_images_data(datas)
|
168
|
+
```
|
134
169
|
|
135
170
|
### From rails
|
136
171
|
|
@@ -149,10 +184,12 @@ Configuration in YAML format will be read and prepanded to options from two path
|
|
149
184
|
|
150
185
|
Example configuration:
|
151
186
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
187
|
+
```yaml
|
188
|
+
nice: 20
|
189
|
+
pngout: false # disable
|
190
|
+
optipng:
|
191
|
+
level: 5
|
192
|
+
```
|
156
193
|
|
157
194
|
## Options
|
158
195
|
|
data/image_optim.gemspec
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'image_optim'
|
5
|
-
s.version = '0.
|
6
|
-
s.summary = %q{Optimize (lossless compress) images (jpeg, png, gif) using external utilities (advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout)}
|
5
|
+
s.version = '0.11.0'
|
6
|
+
s.summary = %q{Optimize (lossless compress) images (jpeg, png, gif, svg) using external utilities (advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout, svgo)}
|
7
7
|
s.homepage = "http://github.com/toy/#{s.name}"
|
8
8
|
s.authors = ['Ivan Kuchin']
|
9
9
|
s.license = 'MIT'
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.require_paths = %w[lib]
|
17
17
|
|
18
18
|
s.add_dependency 'fspath', '~> 2.1.0'
|
19
|
-
s.add_dependency 'image_size', '~> 1.
|
19
|
+
s.add_dependency 'image_size', '~> 1.2.0'
|
20
20
|
s.add_dependency 'exifr', '~> 1.1.3'
|
21
21
|
s.add_dependency 'progress', '~> 3.0.0'
|
22
22
|
s.add_dependency 'in_threads', '~> 1.2.0'
|
data/lib/image_optim/handler.rb
CHANGED
data/lib/image_optim/railtie.rb
CHANGED
@@ -4,7 +4,11 @@ class ImageOptim
|
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
initializer 'image_optim.initializer' do |app|
|
6
6
|
if app.config.assets.compress && app.config.assets.image_optim != false
|
7
|
-
image_optim =
|
7
|
+
image_optim = if app.config.assets.image_optim == true
|
8
|
+
ImageOptim.new
|
9
|
+
else
|
10
|
+
ImageOptim.new(app.config.assets.image_optim || {})
|
11
|
+
end
|
8
12
|
|
9
13
|
processor = proc do |context, data|
|
10
14
|
image_optim.optimize_image_data(data) || data
|
@@ -13,6 +17,7 @@ class ImageOptim
|
|
13
17
|
app.assets.register_preprocessor 'image/gif', :image_optim, &processor
|
14
18
|
app.assets.register_preprocessor 'image/jpeg', :image_optim, &processor
|
15
19
|
app.assets.register_preprocessor 'image/png', :image_optim, &processor
|
20
|
+
app.assets.register_preprocessor 'image/svg+xml', :image_optim, &processor
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
data/lib/image_optim/worker.rb
CHANGED
@@ -52,7 +52,7 @@ class ImageOptim
|
|
52
52
|
|
53
53
|
# List of formats which worker can optimize
|
54
54
|
def image_formats
|
55
|
-
format_from_name = self.class.name.downcase[/gif|jpeg|png/]
|
55
|
+
format_from_name = self.class.name.downcase[/gif|jpeg|png|svg/]
|
56
56
|
raise "#{self.class}: can't guess applicable format from worker name" unless format_from_name
|
57
57
|
[format_from_name.to_sym]
|
58
58
|
end
|
data/lib/image_optim.rb
CHANGED
@@ -75,6 +75,7 @@ class ImageOptim
|
|
75
75
|
worker.optimize(src, dst)
|
76
76
|
end
|
77
77
|
end
|
78
|
+
handler.cleanup
|
78
79
|
if handler.result
|
79
80
|
ImagePath::Optimized.new(handler.result, original)
|
80
81
|
end
|
@@ -182,6 +183,7 @@ end
|
|
182
183
|
pngcrush pngout optipng advpng
|
183
184
|
jhead jpegoptim jpegtran
|
184
185
|
gifsicle
|
186
|
+
svgo
|
185
187
|
].each do |worker|
|
186
188
|
require "image_optim/worker/#{worker}"
|
187
189
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_optim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kuchin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fspath
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: exifr
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/image_optim/worker/optipng.rb
|
131
131
|
- lib/image_optim/worker/pngcrush.rb
|
132
132
|
- lib/image_optim/worker/pngout.rb
|
133
|
+
- lib/image_optim/worker/svgo.rb
|
133
134
|
- script/update_worker_options_in_readme
|
134
135
|
- spec/image_optim/bin_resolver_spec.rb
|
135
136
|
- spec/image_optim/config_spec.rb
|
@@ -153,6 +154,7 @@ files:
|
|
153
154
|
- spec/images/orient/8.jpg
|
154
155
|
- spec/images/orient/generate
|
155
156
|
- spec/images/orient/original.jpg
|
157
|
+
- spec/images/test.svg
|
156
158
|
- spec/images/transparency1.png
|
157
159
|
- spec/images/transparency2.png
|
158
160
|
- spec/images/vergroessert.jpg
|
@@ -180,8 +182,8 @@ rubyforge_project: image_optim
|
|
180
182
|
rubygems_version: 2.0.3
|
181
183
|
signing_key:
|
182
184
|
specification_version: 4
|
183
|
-
summary: Optimize (lossless compress) images (jpeg, png, gif) using external
|
184
|
-
(advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout)
|
185
|
+
summary: Optimize (lossless compress) images (jpeg, png, gif, svg) using external
|
186
|
+
utilities (advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout, svgo)
|
185
187
|
test_files:
|
186
188
|
- spec/image_optim/bin_resolver_spec.rb
|
187
189
|
- spec/image_optim/config_spec.rb
|
@@ -205,6 +207,7 @@ test_files:
|
|
205
207
|
- spec/images/orient/8.jpg
|
206
208
|
- spec/images/orient/generate
|
207
209
|
- spec/images/orient/original.jpg
|
210
|
+
- spec/images/test.svg
|
208
211
|
- spec/images/transparency1.png
|
209
212
|
- spec/images/transparency2.png
|
210
213
|
- spec/images/vergroessert.jpg
|