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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWNmYzAxNjlhZjg3NzNiMjhlZTNiZThhNWVkNDQ0NjQzOGViZjhjMQ==
4
+ NWIyNWIzNTYyNmNhOGViOTE3NWU0NmFiMGYyYjk3NTM3ZDNkYzJhMA==
5
5
  data.tar.gz: !binary |-
6
- ZWVhMDlmOWRhYjgxYjI0MzM2NzA2NzlmODE4MzY2MDQyYjE5NWQ4Mw==
6
+ Mjg0NmZlYTAzYmQyYTQyMDBhNjA0ZTg0MjVlYWIwNTE1MTJiYmE5MQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZmNlNGQzZjBjOTZiYjk0OWI4OWEwZDgxYjc5MGI0YWQ3Y2I1ZTRhNDYxY2Mz
10
- OWM4MTA4YjBlNjc4MWM5NWRlZWYyYmI5NjNlN2FlODRmMmZjOTdiNzEzNzY5
11
- NzZiOTMyZDBkMzVmYTBmY2E4ZTg2YjI1ODViYWFjOTUxODM5OTI=
9
+ Y2QzMDBmZTAwNjY4OGIyNGMwZGNkMmQyZTMyODM3ZTc0NzY3YTE5Y2I4Mzcx
10
+ MmZhZDBjYzc4ZGU4MDE5MTI2YzNiOTgyNTU1NGE0Mzg3NDUzOWNkNGFlM2Jj
11
+ OTY4MGM5NGIxYWRiYjQxNmNiOWI0ZDllY2E3YjUwZjMyNGZmZGM=
12
12
  data.tar.gz: !binary |-
13
- YTk5YTAwZDgwZDYwODJjNmQ1NTcxMTYyNDZlM2I3MTJkNWUwOGU4N2YyNzQz
14
- MmE3YTQwMGI5ZjQ2M2ZlYTQzNzcwOTZjNDE0NjQ2YzM2NGEzOTUwNjRlNzll
15
- ZDAxMDRlMDFjNDgyYmRiYjYyODhhMzBiNDIzOTRmMzFjOGU3NTc=
13
+ NmRjNmMwMDllZDk1ZjFkN2I5NTk1Nzc4ODhlZjFiMWZjMjBiNmQzOTBmZDYy
14
+ MmEzZTFmNWViYTg2NDAzOTM4ZjU0NTViZTJmYWU5MjI4MDcwYjc3ZDY2ZmE5
15
+ YzM5MGE3ZDVmMzA5OTg0NzI4Y2FjNmU0OWZkM2FjNTIxOWNjNDc=
data/.travis.yml CHANGED
@@ -15,5 +15,6 @@ before_install:
15
15
  - wget http://static.jonof.id.au/dl/kenutils/pngout-20130221-linux.tar.gz
16
16
  - tar -xzf pngout-*-linux.tar.gz
17
17
  - mv pngout-*-linux pngout-linux
18
+ - npm install -g svgo
18
19
  env:
19
20
  - PATH=pngout-linux/x86_64:$PATH
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
- gem install image_optim
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
- sudo apt-get install -y advancecomp gifsicle jhead jpegoptim libjpeg-progs optipng pngcrush
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
- sudo yum install -y advancecomp gifsicle jhead libjpeg optipng
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
- cd /tmp
66
- curl -O http://www.kokkonen.net/tjko/src/jpegoptim-1.2.4.tar.gz
67
- tar zxf jpegoptim-1.2.4.tar.gz
68
- cd jpegoptim-1.2.4
69
- ./configure && make && make install
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
- cd /tmp
74
- curl -O http://iweb.dl.sourceforge.net/project/pmt/pngcrush/1.7.43/pngcrush-1.7.43.tar.gz
75
- tar zxf pngcrush-1.7.43.tar.gz
76
- cd pngcrush-1.7.43
77
- make && cp -f pngcrush /usr/local/bin
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
- sudo port install advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush
92
+ ```bash
93
+ sudo port install advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush
94
+ ```
82
95
 
83
96
  ### OS X: Brew
84
97
 
85
- brew install advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush
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
- image_optim *.{jpg,png,gif}
120
+ ```sh
121
+ image_optim *.{jpg,png,gif,svg}
98
122
 
99
- image_optim -h
123
+ image_optim -h
124
+ ```
100
125
 
101
126
  ### From ruby
102
127
 
103
128
  Initilize optimizer:
104
129
 
105
- image_optim = ImageOptim.new
130
+ ```ruby
131
+ image_optim = ImageOptim.new
106
132
 
107
- image_optim = ImageOptim.new(:pngout => false)
133
+ image_optim = ImageOptim.new(:pngout => false)
108
134
 
109
- image_optim = ImageOptim.new(:nice => 20)
135
+ image_optim = ImageOptim.new(:nice => 20)
136
+ ```
110
137
 
111
138
  Optimize image getting temp path:
112
139
 
113
- image_optim.optimize_image('a.png')
140
+ ```ruby
141
+ image_optim.optimize_image('a.png')
142
+ ```
114
143
 
115
144
  Optimize image in place:
116
145
 
117
- image_optim.optimize_image!('b.jpg')
146
+ ```ruby
147
+ image_optim.optimize_image!('b.jpg')
148
+ ```
118
149
 
119
150
  Optimize image data:
120
151
 
121
- image_optim.optimize_image_data(data)
152
+ ```ruby
153
+ image_optim.optimize_image_data(data)
154
+ ```
122
155
 
123
156
  Multiple images:
124
157
 
125
- image_optim.optimize_images(Dir['*.png']) do |unoptimized, optimized|
126
- if optimized
127
- puts "#{unoptimized} => #{optimized}"
128
- end
129
- end
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
- image_optim.optimize_images!(Dir['*.*'])
165
+ image_optim.optimize_images!(Dir['*.*'])
132
166
 
133
- image_optim.optimize_images_data(datas)
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
- nice: 20
153
- pngout: false # disable
154
- optipng:
155
- level: 5
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.10.2'
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.1.2'
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'
@@ -23,5 +23,13 @@ class ImageOptim
23
23
  end
24
24
  end
25
25
  end
26
+
27
+ # Remove extra temp files
28
+ def cleanup
29
+ if @dst
30
+ @dst.unlink
31
+ @dst = nil
32
+ end
33
+ end
26
34
  end
27
35
  end
@@ -43,6 +43,7 @@ class ImageOptim
43
43
  src.copy(temp)
44
44
  temp.write(read)
45
45
  temp.rename(src.to_s)
46
+ unlink
46
47
  end
47
48
  end
48
49
 
@@ -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 = ImageOptim.new
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
@@ -0,0 +1,12 @@
1
+ require 'image_optim/worker'
2
+
3
+ class ImageOptim
4
+ class Worker
5
+ class Svgo < Worker
6
+ def optimize(src, dst)
7
+ args = %W[-i #{src} -o #{dst}]
8
+ execute(:svgo, *args) && optimized?(src, dst)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -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
@@ -40,5 +40,9 @@ describe ImageOptim::Handler do
40
40
  [src, dst].should == [temp_a, temp_b]; true
41
41
  end
42
42
  handler.result.should == temp_b
43
+
44
+ temp_a.should_receive(:unlink).once
45
+ handler.cleanup
46
+ handler.cleanup
43
47
  end
44
48
  end
@@ -0,0 +1,3 @@
1
+ <svg width="1in" height="100" xmlns="http://www.w3.org/2000/svg">
2
+ <circle cx="36" cy="50" r="30" stroke="black" stroke-width="10" fill="red" />
3
+ </svg>
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.10.2
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-01-25 00:00:00.000000000 Z
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.1.2
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.1.2
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 utilities
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