image_optim 0.29.0 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -3
- data/CHANGELOG.markdown +4 -0
- data/README.markdown +2 -1
- data/Vagrantfile +1 -1
- data/image_optim.gemspec +1 -1
- data/lib/image_optim.rb +15 -3
- data/lib/image_optim/bin_resolver/bin.rb +7 -7
- data/lib/image_optim/cache.rb +6 -0
- data/lib/image_optim/cmd.rb +45 -6
- data/lib/image_optim/config.rb +9 -1
- data/lib/image_optim/elapsed_time.rb +26 -0
- data/lib/image_optim/errors.rb +9 -0
- data/lib/image_optim/runner/option_parser.rb +4 -0
- data/lib/image_optim/timer.rb +25 -0
- data/lib/image_optim/worker.rb +24 -12
- data/lib/image_optim/worker/advpng.rb +2 -2
- data/lib/image_optim/worker/gifsicle.rb +3 -3
- data/lib/image_optim/worker/jhead.rb +2 -2
- data/lib/image_optim/worker/jpegoptim.rb +2 -2
- data/lib/image_optim/worker/jpegrecompress.rb +2 -2
- data/lib/image_optim/worker/jpegtran.rb +3 -3
- data/lib/image_optim/worker/optipng.rb +2 -2
- data/lib/image_optim/worker/pngcrush.rb +2 -2
- data/lib/image_optim/worker/pngout.rb +2 -2
- data/lib/image_optim/worker/pngquant.rb +2 -2
- data/lib/image_optim/worker/svgo.rb +2 -2
- data/script/worker_analysis +4 -4
- data/spec/image_optim/bin_resolver_spec.rb +5 -5
- data/spec/image_optim/cache_path_spec.rb +3 -7
- data/spec/image_optim/cache_spec.rb +7 -7
- data/spec/image_optim/cmd_spec.rb +58 -6
- data/spec/image_optim/config_spec.rb +36 -20
- data/spec/image_optim/elapsed_time_spec.rb +14 -0
- data/spec/image_optim/hash_helpers_spec.rb +18 -18
- data/spec/image_optim/option_definition_spec.rb +6 -6
- data/spec/image_optim/path_spec.rb +4 -8
- data/spec/image_optim/runner/option_parser_spec.rb +4 -4
- data/spec/image_optim/timer_spec.rb +32 -0
- data/spec/image_optim/worker/jpegrecompress_spec.rb +2 -2
- data/spec/image_optim/worker/optipng_spec.rb +11 -11
- data/spec/image_optim/worker/pngquant_spec.rb +5 -5
- data/spec/image_optim/worker_spec.rb +17 -17
- data/spec/image_optim_spec.rb +46 -9
- data/spec/spec_helper.rb +16 -15
- metadata +11 -4
data/spec/image_optim_spec.rb
CHANGED
@@ -27,7 +27,7 @@ describe ImageOptim do
|
|
27
27
|
ImageOptim::Worker.klasses.map do |klass|
|
28
28
|
[klass.bin_sym, false]
|
29
29
|
end
|
30
|
-
].merge(:
|
30
|
+
].merge(skip_missing_workers: false)
|
31
31
|
|
32
32
|
ImageOptim::Worker.klasses.each do |worker_klass|
|
33
33
|
describe "#{worker_klass.bin_sym} worker" do
|
@@ -36,7 +36,7 @@ describe ImageOptim do
|
|
36
36
|
|
37
37
|
image_optim = ImageOptim.new(options)
|
38
38
|
if Array(worker_klass.init(image_optim)).empty?
|
39
|
-
image_optim = ImageOptim.new(options.merge(:
|
39
|
+
image_optim = ImageOptim.new(options.merge(allow_lossy: true))
|
40
40
|
end
|
41
41
|
|
42
42
|
expect(test_images.any? do |original|
|
@@ -59,10 +59,10 @@ describe ImageOptim do
|
|
59
59
|
rotated = images_dir / 'orient/original.jpg'
|
60
60
|
rotate_images = images_dir.glob('orient/?.jpg')
|
61
61
|
|
62
|
-
base_options = {:
|
62
|
+
base_options = {skip_missing_workers: false}
|
63
63
|
[
|
64
64
|
['lossless', base_options, 0],
|
65
|
-
['lossy', base_options.merge(:
|
65
|
+
['lossy', base_options.merge(allow_lossy: true), 0.001],
|
66
66
|
].each do |type, options, max_difference|
|
67
67
|
it "does it #{type}" do
|
68
68
|
image_optim = ImageOptim.new(options)
|
@@ -95,8 +95,8 @@ describe ImageOptim do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
{
|
98
|
-
:
|
99
|
-
:
|
98
|
+
png: "\211PNG\r\n\032\n",
|
99
|
+
jpeg: "\377\330",
|
100
100
|
}.each do |type, data|
|
101
101
|
it "ingores broken #{type}" do
|
102
102
|
path = FSPath.temp_file_path
|
@@ -105,12 +105,49 @@ describe ImageOptim do
|
|
105
105
|
expect(ImageOptim.optimize_image(path)).to be_nil
|
106
106
|
end
|
107
107
|
end
|
108
|
+
|
109
|
+
context 'using timeout' do
|
110
|
+
let(:timeout){ 123 }
|
111
|
+
let(:image_optim){ ImageOptim.new(isolated_options_base.merge(timeout: timeout)) }
|
112
|
+
let(:timer){ instance_double(ImageOptim::Timer) }
|
113
|
+
let(:workers){ Array.new(3){ instance_double(ImageOptim::Worker) } }
|
114
|
+
let(:path){ test_images.first }
|
115
|
+
|
116
|
+
before do
|
117
|
+
allow(ImageOptim::Timer).to receive(:new).with(timeout).and_return(timer)
|
118
|
+
allow(image_optim).to receive(:workers_for_image).and_return(workers)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'sends timeout to every worker' do
|
122
|
+
some_path = instance_of(ImageOptim::Path)
|
123
|
+
|
124
|
+
expect(workers[0]).to receive(:optimize).with(some_path, some_path, timeout: timer)
|
125
|
+
expect(workers[1]).to receive(:optimize).with(some_path, some_path, timeout: timer)
|
126
|
+
expect(workers[2]).to receive(:optimize).with(some_path, some_path, timeout: timer)
|
127
|
+
|
128
|
+
image_optim.optimize_image(path)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'returns nil if there was no success before worker times out' do
|
132
|
+
allow(workers[0]).to receive(:optimize).and_return(false)
|
133
|
+
allow(workers[1]).to receive(:optimize).and_raise(ImageOptim::Errors::TimeoutExceeded)
|
134
|
+
|
135
|
+
expect(image_optim.optimize_image(path)).to be_nil
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'returns result if there was success before worker times out' do
|
139
|
+
allow(workers[0]).to receive(:optimize).and_return(true)
|
140
|
+
allow(workers[1]).to receive(:optimize).and_raise(ImageOptim::Errors::TimeoutExceeded)
|
141
|
+
|
142
|
+
expect(image_optim.optimize_image(path)).to be_an(ImageOptim::OptimizedPath)
|
143
|
+
end
|
144
|
+
end
|
108
145
|
end
|
109
146
|
|
110
147
|
describe '#optimize_image!' do
|
111
148
|
it 'optimizes image and replaces original' do
|
112
149
|
original = double
|
113
|
-
optimized = double(:
|
150
|
+
optimized = double(original_size: 12_345)
|
114
151
|
optimized_wrap = double
|
115
152
|
image_optim = ImageOptim.new
|
116
153
|
|
@@ -144,7 +181,7 @@ describe ImageOptim do
|
|
144
181
|
describe '#optimize_image_data' do
|
145
182
|
it 'create temp file, optimizes image and returns data' do
|
146
183
|
data = double
|
147
|
-
temp = double(:
|
184
|
+
temp = double(path: double)
|
148
185
|
optimized = double
|
149
186
|
optimized_data = double
|
150
187
|
image_optim = ImageOptim.new
|
@@ -165,7 +202,7 @@ describe ImageOptim do
|
|
165
202
|
|
166
203
|
it 'returns nil if optimization fails' do
|
167
204
|
data = double
|
168
|
-
temp = double(:
|
205
|
+
temp = double(path: double)
|
169
206
|
image_optim = ImageOptim.new
|
170
207
|
|
171
208
|
allow(ImageOptim::ImageMeta).to receive(:format_for_data).
|
data/spec/spec_helper.rb
CHANGED
@@ -75,22 +75,23 @@ RSpec::Matchers.define :be_similar_to do |expected, max_difference|
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
SkipConditions = Hash.new do |cache, name|
|
79
|
+
cache[name] = case name
|
80
|
+
when :any_file_mode_allowed
|
81
|
+
Tempfile.open('posix') do |f|
|
81
82
|
File.chmod(0, f.path)
|
82
|
-
|
83
|
+
'full file modes are not support' unless (File.stat(f.path).mode & 0o777).zero?
|
83
84
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
85
|
+
when :inodes_support
|
86
|
+
'inodes are not supported' if File.stat(__FILE__).ino.zero?
|
87
|
+
when :signals_support
|
88
|
+
begin
|
89
|
+
Process.kill(0, 0)
|
90
|
+
nil
|
91
|
+
rescue
|
92
|
+
'signals are not supported'
|
93
|
+
end
|
94
|
+
else
|
95
|
+
fail "Unknown check #{name}"
|
95
96
|
end
|
96
97
|
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.30.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: 2021-
|
11
|
+
date: 2021-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fspath
|
@@ -191,6 +191,8 @@ files:
|
|
191
191
|
- lib/image_optim/cmd.rb
|
192
192
|
- lib/image_optim/config.rb
|
193
193
|
- lib/image_optim/configuration_error.rb
|
194
|
+
- lib/image_optim/elapsed_time.rb
|
195
|
+
- lib/image_optim/errors.rb
|
194
196
|
- lib/image_optim/handler.rb
|
195
197
|
- lib/image_optim/hash_helpers.rb
|
196
198
|
- lib/image_optim/image_meta.rb
|
@@ -203,6 +205,7 @@ files:
|
|
203
205
|
- lib/image_optim/runner/glob_helpers.rb
|
204
206
|
- lib/image_optim/runner/option_parser.rb
|
205
207
|
- lib/image_optim/space.rb
|
208
|
+
- lib/image_optim/timer.rb
|
206
209
|
- lib/image_optim/true_false_nil.rb
|
207
210
|
- lib/image_optim/worker.rb
|
208
211
|
- lib/image_optim/worker/advpng.rb
|
@@ -229,6 +232,7 @@ files:
|
|
229
232
|
- spec/image_optim/cache_spec.rb
|
230
233
|
- spec/image_optim/cmd_spec.rb
|
231
234
|
- spec/image_optim/config_spec.rb
|
235
|
+
- spec/image_optim/elapsed_time_spec.rb
|
232
236
|
- spec/image_optim/handler_spec.rb
|
233
237
|
- spec/image_optim/hash_helpers_spec.rb
|
234
238
|
- spec/image_optim/image_meta_spec.rb
|
@@ -239,6 +243,7 @@ files:
|
|
239
243
|
- spec/image_optim/runner/glob_helpers_spec.rb
|
240
244
|
- spec/image_optim/runner/option_parser_spec.rb
|
241
245
|
- spec/image_optim/space_spec.rb
|
246
|
+
- spec/image_optim/timer_spec.rb
|
242
247
|
- spec/image_optim/worker/jpegrecompress_spec.rb
|
243
248
|
- spec/image_optim/worker/optipng_spec.rb
|
244
249
|
- spec/image_optim/worker/pngquant_spec.rb
|
@@ -279,7 +284,7 @@ licenses:
|
|
279
284
|
metadata:
|
280
285
|
bug_tracker_uri: https://github.com/toy/image_optim/issues
|
281
286
|
changelog_uri: https://github.com/toy/image_optim/blob/master/CHANGELOG.markdown
|
282
|
-
documentation_uri: https://www.rubydoc.info/gems/image_optim/0.
|
287
|
+
documentation_uri: https://www.rubydoc.info/gems/image_optim/0.30.0
|
283
288
|
source_code_uri: https://github.com/toy/image_optim
|
284
289
|
post_install_message: |
|
285
290
|
Rails image assets optimization is extracted into image_optim_rails gem
|
@@ -298,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
298
303
|
- !ruby/object:Gem::Version
|
299
304
|
version: '0'
|
300
305
|
requirements: []
|
301
|
-
rubygems_version: 3.
|
306
|
+
rubygems_version: 3.2.16
|
302
307
|
signing_key:
|
303
308
|
specification_version: 4
|
304
309
|
summary: Command line tool and ruby interface to optimize (lossless compress, optionally
|
@@ -313,6 +318,7 @@ test_files:
|
|
313
318
|
- spec/image_optim/cache_spec.rb
|
314
319
|
- spec/image_optim/cmd_spec.rb
|
315
320
|
- spec/image_optim/config_spec.rb
|
321
|
+
- spec/image_optim/elapsed_time_spec.rb
|
316
322
|
- spec/image_optim/handler_spec.rb
|
317
323
|
- spec/image_optim/hash_helpers_spec.rb
|
318
324
|
- spec/image_optim/image_meta_spec.rb
|
@@ -323,6 +329,7 @@ test_files:
|
|
323
329
|
- spec/image_optim/runner/glob_helpers_spec.rb
|
324
330
|
- spec/image_optim/runner/option_parser_spec.rb
|
325
331
|
- spec/image_optim/space_spec.rb
|
332
|
+
- spec/image_optim/timer_spec.rb
|
326
333
|
- spec/image_optim/worker/jpegrecompress_spec.rb
|
327
334
|
- spec/image_optim/worker/optipng_spec.rb
|
328
335
|
- spec/image_optim/worker/pngquant_spec.rb
|