image_optim 0.27.1 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.appveyor.yml +2 -0
- data/.github/workflows/check.yml +59 -0
- data/.pre-commit-hooks.yaml +9 -0
- data/.rubocop.yml +6 -3
- data/CHANGELOG.markdown +22 -0
- data/CONTRIBUTING.markdown +5 -2
- data/Gemfile +1 -7
- data/LICENSE.txt +1 -1
- data/README.markdown +21 -10
- data/Vagrantfile +1 -1
- data/image_optim.gemspec +7 -4
- data/lib/image_optim/bin_resolver/bin.rb +10 -9
- data/lib/image_optim/cache.rb +6 -0
- data/lib/image_optim/cmd.rb +45 -6
- data/lib/image_optim/config.rb +14 -8
- data/lib/image_optim/elapsed_time.rb +26 -0
- data/lib/image_optim/errors.rb +9 -0
- data/lib/image_optim/path.rb +1 -1
- data/lib/image_optim/runner/option_parser.rb +24 -18
- data/lib/image_optim/runner.rb +1 -1
- data/lib/image_optim/timer.rb +25 -0
- data/lib/image_optim/worker/advpng.rb +7 -7
- data/lib/image_optim/worker/gifsicle.rb +11 -11
- data/lib/image_optim/worker/jhead.rb +2 -2
- data/lib/image_optim/worker/jpegoptim.rb +13 -11
- data/lib/image_optim/worker/jpegrecompress.rb +17 -2
- data/lib/image_optim/worker/jpegtran.rb +4 -4
- data/lib/image_optim/worker/optipng.rb +7 -7
- data/lib/image_optim/worker/oxipng.rb +53 -0
- data/lib/image_optim/worker/pngcrush.rb +6 -6
- data/lib/image_optim/worker/pngout.rb +7 -7
- data/lib/image_optim/worker/pngquant.rb +10 -9
- data/lib/image_optim/worker/svgo.rb +2 -2
- data/lib/image_optim/worker.rb +32 -29
- data/lib/image_optim.rb +16 -10
- data/script/update_worker_options_in_readme +2 -2
- data/script/worker_analysis +16 -18
- data/spec/image_optim/bin_resolver_spec.rb +5 -5
- data/spec/image_optim/cache_path_spec.rb +7 -10
- data/spec/image_optim/cache_spec.rb +8 -8
- data/spec/image_optim/cmd_spec.rb +64 -6
- data/spec/image_optim/config_spec.rb +36 -20
- data/spec/image_optim/elapsed_time_spec.rb +14 -0
- data/spec/image_optim/handler_spec.rb +1 -1
- 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 +8 -11
- 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 +32 -0
- data/spec/image_optim/worker/optipng_spec.rb +11 -11
- data/spec/image_optim/worker/oxipng_spec.rb +89 -0
- 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 +47 -10
- data/spec/images/invisiblepixels/generate +1 -1
- data/spec/spec_helper.rb +18 -17
- metadata +36 -15
- data/.travis.yml +0 -49
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).
|
@@ -216,7 +253,7 @@ describe ImageOptim do
|
|
216
253
|
|
217
254
|
describe 'given block' do
|
218
255
|
it 'optimizes images, yields path and result for each and '\
|
219
|
-
|
256
|
+
'returns array of yield results' do
|
220
257
|
image_optim = ImageOptim.new
|
221
258
|
results = test_images.map do |src|
|
222
259
|
dst = double
|
@@ -17,7 +17,7 @@ IO.popen(%W[
|
|
17
17
|
].shelljoin, 'w') do |f|
|
18
18
|
side.times do |a|
|
19
19
|
side.times do |b|
|
20
|
-
alpha = [0, 1, 0x7f, 0xff][(a / 8 + b / 8) % 4]
|
20
|
+
alpha = [0, 1, 0x7f, 0xff][((a / 8) + (b / 8)) % 4]
|
21
21
|
f << [rand(256), rand(256), rand(256), alpha].pack('C*')
|
22
22
|
end
|
23
23
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
if ENV['
|
3
|
+
if ENV['CC_TEST_REPORTER_ID']
|
4
4
|
require 'simplecov'
|
5
5
|
SimpleCov.start
|
6
6
|
end
|
@@ -71,26 +71,27 @@ RSpec::Matchers.define :be_similar_to do |expected, max_difference|
|
|
71
71
|
end
|
72
72
|
failure_message do |actual|
|
73
73
|
"expected #{actual} to have at most #{max_difference} difference from "\
|
74
|
-
|
74
|
+
"#{expected}, got normalized root-mean-square error of #{@diff}"
|
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.31.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:
|
11
|
+
date: 2021-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fspath
|
@@ -138,20 +138,28 @@ dependencies:
|
|
138
138
|
requirements:
|
139
139
|
- - "~>"
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version: '0
|
142
|
-
- - "!="
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
version: 0.78.0
|
141
|
+
version: '1.0'
|
145
142
|
type: :development
|
146
143
|
prerelease: false
|
147
144
|
version_requirements: !ruby/object:Gem::Requirement
|
148
145
|
requirements:
|
149
146
|
- - "~>"
|
150
147
|
- !ruby/object:Gem::Version
|
151
|
-
version: '0
|
152
|
-
|
148
|
+
version: '1.0'
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: rubocop-rspec
|
151
|
+
requirement: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - "~>"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '2.0'
|
156
|
+
type: :development
|
157
|
+
prerelease: false
|
158
|
+
version_requirements: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - "~>"
|
153
161
|
- !ruby/object:Gem::Version
|
154
|
-
version:
|
162
|
+
version: '2.0'
|
155
163
|
description:
|
156
164
|
email:
|
157
165
|
executables:
|
@@ -160,9 +168,10 @@ extensions: []
|
|
160
168
|
extra_rdoc_files: []
|
161
169
|
files:
|
162
170
|
- ".appveyor.yml"
|
171
|
+
- ".github/workflows/check.yml"
|
163
172
|
- ".gitignore"
|
173
|
+
- ".pre-commit-hooks.yaml"
|
164
174
|
- ".rubocop.yml"
|
165
|
-
- ".travis.yml"
|
166
175
|
- CHANGELOG.markdown
|
167
176
|
- CONTRIBUTING.markdown
|
168
177
|
- Gemfile
|
@@ -182,6 +191,8 @@ files:
|
|
182
191
|
- lib/image_optim/cmd.rb
|
183
192
|
- lib/image_optim/config.rb
|
184
193
|
- lib/image_optim/configuration_error.rb
|
194
|
+
- lib/image_optim/elapsed_time.rb
|
195
|
+
- lib/image_optim/errors.rb
|
185
196
|
- lib/image_optim/handler.rb
|
186
197
|
- lib/image_optim/hash_helpers.rb
|
187
198
|
- lib/image_optim/image_meta.rb
|
@@ -194,6 +205,7 @@ files:
|
|
194
205
|
- lib/image_optim/runner/glob_helpers.rb
|
195
206
|
- lib/image_optim/runner/option_parser.rb
|
196
207
|
- lib/image_optim/space.rb
|
208
|
+
- lib/image_optim/timer.rb
|
197
209
|
- lib/image_optim/true_false_nil.rb
|
198
210
|
- lib/image_optim/worker.rb
|
199
211
|
- lib/image_optim/worker/advpng.rb
|
@@ -204,6 +216,7 @@ files:
|
|
204
216
|
- lib/image_optim/worker/jpegrecompress.rb
|
205
217
|
- lib/image_optim/worker/jpegtran.rb
|
206
218
|
- lib/image_optim/worker/optipng.rb
|
219
|
+
- lib/image_optim/worker/oxipng.rb
|
207
220
|
- lib/image_optim/worker/pngcrush.rb
|
208
221
|
- lib/image_optim/worker/pngout.rb
|
209
222
|
- lib/image_optim/worker/pngquant.rb
|
@@ -220,6 +233,7 @@ files:
|
|
220
233
|
- spec/image_optim/cache_spec.rb
|
221
234
|
- spec/image_optim/cmd_spec.rb
|
222
235
|
- spec/image_optim/config_spec.rb
|
236
|
+
- spec/image_optim/elapsed_time_spec.rb
|
223
237
|
- spec/image_optim/handler_spec.rb
|
224
238
|
- spec/image_optim/hash_helpers_spec.rb
|
225
239
|
- spec/image_optim/image_meta_spec.rb
|
@@ -230,7 +244,10 @@ files:
|
|
230
244
|
- spec/image_optim/runner/glob_helpers_spec.rb
|
231
245
|
- spec/image_optim/runner/option_parser_spec.rb
|
232
246
|
- spec/image_optim/space_spec.rb
|
247
|
+
- spec/image_optim/timer_spec.rb
|
248
|
+
- spec/image_optim/worker/jpegrecompress_spec.rb
|
233
249
|
- spec/image_optim/worker/optipng_spec.rb
|
250
|
+
- spec/image_optim/worker/oxipng_spec.rb
|
234
251
|
- spec/image_optim/worker/pngquant_spec.rb
|
235
252
|
- spec/image_optim/worker_spec.rb
|
236
253
|
- spec/image_optim_spec.rb
|
@@ -269,7 +286,7 @@ licenses:
|
|
269
286
|
metadata:
|
270
287
|
bug_tracker_uri: https://github.com/toy/image_optim/issues
|
271
288
|
changelog_uri: https://github.com/toy/image_optim/blob/master/CHANGELOG.markdown
|
272
|
-
documentation_uri: https://www.rubydoc.info/gems/image_optim/0.
|
289
|
+
documentation_uri: https://www.rubydoc.info/gems/image_optim/0.31.0
|
273
290
|
source_code_uri: https://github.com/toy/image_optim
|
274
291
|
post_install_message: |
|
275
292
|
Rails image assets optimization is extracted into image_optim_rails gem
|
@@ -281,20 +298,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
281
298
|
requirements:
|
282
299
|
- - ">="
|
283
300
|
- !ruby/object:Gem::Version
|
284
|
-
version:
|
301
|
+
version: 1.9.3
|
285
302
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
286
303
|
requirements:
|
287
304
|
- - ">="
|
288
305
|
- !ruby/object:Gem::Version
|
289
306
|
version: '0'
|
290
307
|
requirements: []
|
291
|
-
rubygems_version: 3.
|
308
|
+
rubygems_version: 3.2.28
|
292
309
|
signing_key:
|
293
310
|
specification_version: 4
|
294
311
|
summary: Command line tool and ruby interface to optimize (lossless compress, optionally
|
295
312
|
lossy) jpeg, png, gif and svg images using external utilities (advpng, gifsicle,
|
296
|
-
jhead, jpeg-recompress, jpegoptim, jpegrescan, jpegtran, optipng,
|
297
|
-
pngquant, svgo)
|
313
|
+
jhead, jpeg-recompress, jpegoptim, jpegrescan, jpegtran, optipng, oxipng, pngcrush,
|
314
|
+
pngout, pngquant, svgo)
|
298
315
|
test_files:
|
299
316
|
- spec/image_optim/bin_resolver/comparable_condition_spec.rb
|
300
317
|
- spec/image_optim/bin_resolver/simple_version_spec.rb
|
@@ -303,6 +320,7 @@ test_files:
|
|
303
320
|
- spec/image_optim/cache_spec.rb
|
304
321
|
- spec/image_optim/cmd_spec.rb
|
305
322
|
- spec/image_optim/config_spec.rb
|
323
|
+
- spec/image_optim/elapsed_time_spec.rb
|
306
324
|
- spec/image_optim/handler_spec.rb
|
307
325
|
- spec/image_optim/hash_helpers_spec.rb
|
308
326
|
- spec/image_optim/image_meta_spec.rb
|
@@ -313,7 +331,10 @@ test_files:
|
|
313
331
|
- spec/image_optim/runner/glob_helpers_spec.rb
|
314
332
|
- spec/image_optim/runner/option_parser_spec.rb
|
315
333
|
- spec/image_optim/space_spec.rb
|
334
|
+
- spec/image_optim/timer_spec.rb
|
335
|
+
- spec/image_optim/worker/jpegrecompress_spec.rb
|
316
336
|
- spec/image_optim/worker/optipng_spec.rb
|
337
|
+
- spec/image_optim/worker/oxipng_spec.rb
|
317
338
|
- spec/image_optim/worker/pngquant_spec.rb
|
318
339
|
- spec/image_optim/worker_spec.rb
|
319
340
|
- spec/image_optim_spec.rb
|
data/.travis.yml
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
dist: trusty
|
3
|
-
language: ruby
|
4
|
-
cache:
|
5
|
-
bundler: true
|
6
|
-
directories:
|
7
|
-
- $(npm root)
|
8
|
-
- ~/bin
|
9
|
-
rvm:
|
10
|
-
- '1.8.7-p374'
|
11
|
-
- '1.9.3-p551'
|
12
|
-
- '2.0.0-p648'
|
13
|
-
- '2.1.10'
|
14
|
-
- '2.2.10'
|
15
|
-
- '2.3.8'
|
16
|
-
- '2.4.10'
|
17
|
-
- '2.5.8'
|
18
|
-
- '2.6.6'
|
19
|
-
- '2.7.1'
|
20
|
-
- 'jruby-9.2.11.1'
|
21
|
-
script:
|
22
|
-
- bundle exec image_optim --info
|
23
|
-
- bundle exec rspec
|
24
|
-
before_install:
|
25
|
-
- 'echo "gem: --no-ri --no-rdoc --no-document" > ~/.gemrc'
|
26
|
-
- gem install rubygems-update || gem install rubygems-update --version '< 3'
|
27
|
-
- update_rubygems
|
28
|
-
- gem install bundler || gem install bundler --version '< 2'
|
29
|
-
- nvm install stable
|
30
|
-
- mkdir -p ~/bin
|
31
|
-
- command -v svgo || npm install -g svgo
|
32
|
-
- command -v pngout || curl -L "https://www.jonof.id.au/files/kenutils/pngout-20200115-linux.tar.gz" | tar -xz -C ~/bin --strip-components 2 --wildcards '*/amd64/pngout'
|
33
|
-
matrix:
|
34
|
-
include:
|
35
|
-
- env: CODECLIMATE=1
|
36
|
-
rvm: '2.4.10'
|
37
|
-
after_success: bundle exec codeclimate-test-reporter
|
38
|
-
- env: RUBOCOP=1
|
39
|
-
rvm: '2.4.10'
|
40
|
-
script: bundle exec rubocop
|
41
|
-
before_install: gem update --system && gem install bundler
|
42
|
-
- env: CHECK_RUBIES=1
|
43
|
-
rvm: '2.4.10'
|
44
|
-
script: bundle exec travis_check_rubies
|
45
|
-
before_install: gem update --system && gem install bundler
|
46
|
-
addons:
|
47
|
-
code_climate:
|
48
|
-
repo_token:
|
49
|
-
secure: FDikT3JnOJHOAFSaKwVPB1VOphU0sSzAnzQ+YjSt9XFE+9uFQHth/j4rFoVoqALhCj+47trv6spwkbcSjGCVzm+87OI80GkLCCzNjDOz2W4sP9JWItVgS1VoWW+ioPxpLgpguTb3wutwKOUMEAf+40EX657ZiHumM7nNHrF+RCU=
|