image_optim 0.26.5 → 0.30.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.appveyor.yml +2 -0
  3. data/.pre-commit-hooks.yaml +9 -0
  4. data/.rubocop.yml +33 -14
  5. data/.travis.yml +17 -15
  6. data/CHANGELOG.markdown +26 -0
  7. data/CONTRIBUTING.markdown +4 -1
  8. data/LICENSE.txt +1 -1
  9. data/README.markdown +9 -3
  10. data/Vagrantfile +1 -1
  11. data/image_optim.gemspec +7 -4
  12. data/lib/image_optim.rb +15 -9
  13. data/lib/image_optim/bin_resolver/bin.rb +10 -8
  14. data/lib/image_optim/bin_resolver/comparable_condition.rb +1 -0
  15. data/lib/image_optim/cache.rb +6 -0
  16. data/lib/image_optim/cache_path.rb +19 -2
  17. data/lib/image_optim/cmd.rb +45 -6
  18. data/lib/image_optim/config.rb +13 -7
  19. data/lib/image_optim/elapsed_time.rb +26 -0
  20. data/lib/image_optim/errors.rb +9 -0
  21. data/lib/image_optim/optimized_path.rb +1 -1
  22. data/lib/image_optim/path.rb +29 -6
  23. data/lib/image_optim/runner/option_parser.rb +6 -0
  24. data/lib/image_optim/timer.rb +25 -0
  25. data/lib/image_optim/worker.rb +29 -26
  26. data/lib/image_optim/worker/advpng.rb +2 -2
  27. data/lib/image_optim/worker/class_methods.rb +2 -0
  28. data/lib/image_optim/worker/gifsicle.rb +3 -3
  29. data/lib/image_optim/worker/jhead.rb +2 -2
  30. data/lib/image_optim/worker/jpegoptim.rb +8 -6
  31. data/lib/image_optim/worker/jpegrecompress.rb +17 -2
  32. data/lib/image_optim/worker/jpegtran.rb +3 -3
  33. data/lib/image_optim/worker/optipng.rb +4 -4
  34. data/lib/image_optim/worker/pngcrush.rb +4 -4
  35. data/lib/image_optim/worker/pngout.rb +2 -2
  36. data/lib/image_optim/worker/pngquant.rb +3 -2
  37. data/lib/image_optim/worker/svgo.rb +2 -2
  38. data/script/update_worker_options_in_readme +1 -1
  39. data/script/worker_analysis +20 -19
  40. data/spec/image_optim/bin_resolver_spec.rb +5 -5
  41. data/spec/image_optim/cache_path_spec.rb +67 -28
  42. data/spec/image_optim/cache_spec.rb +10 -8
  43. data/spec/image_optim/cmd_spec.rb +58 -6
  44. data/spec/image_optim/config_spec.rb +36 -20
  45. data/spec/image_optim/elapsed_time_spec.rb +14 -0
  46. data/spec/image_optim/hash_helpers_spec.rb +18 -18
  47. data/spec/image_optim/option_definition_spec.rb +6 -6
  48. data/spec/image_optim/path_spec.rb +61 -26
  49. data/spec/image_optim/runner/option_parser_spec.rb +4 -4
  50. data/spec/image_optim/timer_spec.rb +32 -0
  51. data/spec/image_optim/worker/jpegrecompress_spec.rb +32 -0
  52. data/spec/image_optim/worker/optipng_spec.rb +11 -11
  53. data/spec/image_optim/worker/pngquant_spec.rb +5 -5
  54. data/spec/image_optim/worker_spec.rb +17 -17
  55. data/spec/image_optim_spec.rb +50 -12
  56. data/spec/images/quant/generate +2 -2
  57. data/spec/spec_helper.rb +16 -15
  58. metadata +36 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47d63cf5bc17ca54df17e3f0208edba04654f50479d81f36eadbcccab100a7bb
4
- data.tar.gz: 6638bec36d88903a81bb5f94999b86fac22756cae0b1b98cc75a5ace2e794cd0
3
+ metadata.gz: 0fb8179d2e5c5236278611842ad5dbb3ab39fc1ff92bbd50ed9dae6ccd931bf5
4
+ data.tar.gz: 83ab00c10f205a164ea66f51b6964d3fb4fa7d019c30e472496a0e21879242c0
5
5
  SHA512:
6
- metadata.gz: 581fbe170f547949f2c5e66e0a69256b2864c198297ce56a1e2ac7391ad80f9db35b496b9cb0a80883176c612e25601b4d06f4b099c0f55fb9bb6e1864440dba
7
- data.tar.gz: dd8ead30e38599997fe62af647141c35f8be0876f2e6266862e73a6545f7a5f503ecbd6f126d449214c7ae1b9302a67efd47fa0fad4da3debf9d50499fc12b13
6
+ metadata.gz: 901e787f11a9829b96dd40f0d8aff14d4f2ac691ff3eaa8486d2915fd020b2f6e0d7425b360cf3bdbc52018afd69508078b69dd4e7846a138d9d5e9ea3b613d7
7
+ data.tar.gz: 8a21b871165184221bf9af9b9647f144a21e5da1ebe03680ac54b09edf955068f0364da1ee0d6d8dd9976bb96c76ff0cdcf49cb005f43fd5c5cdfe3f51cde39f
data/.appveyor.yml CHANGED
@@ -6,6 +6,8 @@ install:
6
6
  - gem --version
7
7
  - bundle package --all
8
8
 
9
+ - ps: Install-Product node
10
+
9
11
  - ps: git --work-tree=tmp\bin checkout origin/windows-binaries -- '*.exe'
10
12
 
11
13
  - ps: | # svgo
@@ -0,0 +1,9 @@
1
+ - id: image_optim
2
+ name: image_optim
3
+ entry: image_optim
4
+ language: ruby
5
+ types:
6
+ - image
7
+ args: []
8
+ additional_dependencies:
9
+ - image_optim_pack
data/.rubocop.yml CHANGED
@@ -2,6 +2,7 @@ AllCops:
2
2
  Exclude:
3
3
  - '*.gemspec'
4
4
  - 'vendor/**/*'
5
+ NewCops: enable
5
6
 
6
7
  Bundler/OrderedGems:
7
8
  Enabled: false
@@ -9,6 +10,9 @@ Bundler/OrderedGems:
9
10
  Layout/AccessModifierIndentation:
10
11
  EnforcedStyle: outdent
11
12
 
13
+ Layout/AssignmentIndentation:
14
+ Enabled: false
15
+
12
16
  Layout/CaseIndentation:
13
17
  EnforcedStyle: end
14
18
 
@@ -18,18 +22,18 @@ Layout/DotPosition:
18
22
  Layout/EndAlignment:
19
23
  EnforcedStyleAlignWith: variable
20
24
 
21
- Layout/IndentFirstArrayElement:
25
+ Layout/FirstArrayElementIndentation:
22
26
  EnforcedStyle: consistent
23
27
 
24
- Layout/IndentAssignment:
25
- Enabled: false
26
-
27
- Layout/IndentFirstHashElement:
28
+ Layout/FirstHashElementIndentation:
28
29
  EnforcedStyle: consistent
29
30
 
30
- Layout/IndentHeredoc:
31
+ Layout/HeredocIndentation:
31
32
  Enabled: false
32
33
 
34
+ Layout/LineLength:
35
+ Max: 120
36
+
33
37
  Layout/RescueEnsureAlignment:
34
38
  Enabled: false
35
39
 
@@ -47,10 +51,10 @@ Lint/AmbiguousBlockAssociation:
47
51
  Lint/NestedPercentLiteral:
48
52
  Enabled: false
49
53
 
50
- Lint/UnneededRequireStatement:
54
+ Lint/RedundantRequireStatement:
51
55
  Enabled: false
52
56
 
53
- Lint/UnneededSplatExpansion:
57
+ Lint/RedundantSplatExpansion:
54
58
  Enabled: false
55
59
 
56
60
  Metrics/AbcSize:
@@ -68,19 +72,19 @@ Metrics/ClassLength:
68
72
  Metrics/CyclomaticComplexity:
69
73
  Max: 11
70
74
 
71
- Metrics/LineLength:
72
- Max: 120
73
-
74
75
  Metrics/MethodLength:
75
76
  Max: 25
76
77
 
77
78
  Metrics/PerceivedComplexity:
78
- Max: 8
79
+ Max: 10
79
80
 
80
81
  Security/MarshalLoad:
81
82
  Exclude:
82
83
  - 'script/worker_analysis'
83
84
 
85
+ Style/AccessorGrouping:
86
+ Enabled: false
87
+
84
88
  Style/Alias:
85
89
  EnforcedStyle: prefer_alias_method
86
90
 
@@ -99,8 +103,17 @@ Style/ExpandPathArguments:
99
103
  Style/FormatStringToken:
100
104
  Enabled: false
101
105
 
102
- Style/HashSyntax:
103
- EnforcedStyle: hash_rockets
106
+ Style/HashConversion:
107
+ Enabled: false
108
+
109
+ Style/HashEachMethods:
110
+ Enabled: true
111
+
112
+ Style/HashTransformKeys:
113
+ Enabled: false
114
+
115
+ Style/HashTransformValues:
116
+ Enabled: false
104
117
 
105
118
  Style/IfUnlessModifier:
106
119
  Enabled: false
@@ -108,9 +121,15 @@ Style/IfUnlessModifier:
108
121
  Style/NumericPredicate:
109
122
  EnforcedStyle: comparison
110
123
 
124
+ Style/OptionalBooleanParameter:
125
+ Enabled: false
126
+
111
127
  Style/ParallelAssignment:
112
128
  Enabled: false
113
129
 
130
+ Style/RedundantBegin:
131
+ Enabled: false
132
+
114
133
  Style/RescueStandardError:
115
134
  EnforcedStyle: implicit
116
135
 
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
- sudo: false
1
+ dist: xenial
2
2
  language: ruby
3
3
  cache:
4
4
  bundler: true
@@ -6,38 +6,40 @@ cache:
6
6
  - $(npm root)
7
7
  - ~/bin
8
8
  rvm:
9
- - '1.8.7-p371'
10
9
  - '1.9.3-p551'
11
10
  - '2.0.0-p648'
12
11
  - '2.1.10'
13
12
  - '2.2.10'
14
13
  - '2.3.8'
15
- - '2.4.6'
16
- - '2.5.5'
17
- - '2.6.3'
18
- - 'jruby-9.1.9.0'
14
+ - '2.4.10'
15
+ - '2.5.9'
16
+ - '2.6.7'
17
+ - '2.7.3'
18
+ - '3.0.1'
19
+ - 'jruby-9.2.14.0'
19
20
  script:
20
21
  - bundle exec image_optim --info
21
22
  - bundle exec rspec
22
23
  before_install:
24
+ - 'echo "gem: --no-ri --no-rdoc --no-document" > ~/.gemrc'
23
25
  - gem install rubygems-update || gem install rubygems-update --version '< 3'
24
- - gem update --system
26
+ - update_rubygems
25
27
  - gem install bundler || gem install bundler --version '< 2'
26
28
  - nvm install stable
27
- - mkdir -p ~/bin
28
29
  - command -v svgo || npm install -g svgo
29
- - command -v pngout || curl -L "http://static.jonof.id.au/dl/kenutils/pngout-20150319-linux.tar.gz" | tar -xz -C ~/bin --strip-components 2 --wildcards '*/x86_64/pngout'
30
+ - mkdir -p ~/bin
31
+ - 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'
30
32
  matrix:
31
33
  include:
32
- - env: CODECLIMATE=✓
33
- rvm: '2.4.6'
34
+ - env: CODECLIMATE=1
35
+ rvm: '2.4.10'
34
36
  after_success: bundle exec codeclimate-test-reporter
35
- - env: RUBOCOP=✓
36
- rvm: '2.4.6'
37
+ - env: RUBOCOP=1
38
+ rvm: '2.4.10'
37
39
  script: bundle exec rubocop
38
40
  before_install: gem update --system && gem install bundler
39
- - env: CHECK_RUBIES=✓
40
- rvm: '2.4.6'
41
+ - env: CHECK_RUBIES=1
42
+ rvm: '2.4.10'
41
43
  script: bundle exec travis_check_rubies
42
44
  before_install: gem update --system && gem install bundler
43
45
  addons:
data/CHANGELOG.markdown CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  ## unreleased
4
4
 
5
+ ## v0.30.0 (2021-05-11)
6
+
7
+ * Add `timeout` option to restrict maximum time spent on every image [#21](https://github.com/toy/image_optim/issues/21) [#148](https://github.com/toy/image_optim/pull/148) [#149](https://github.com/toy/image_optim/pull/149) [#162](https://github.com/toy/image_optim/pull/162) [#184](https://github.com/toy/image_optim/pull/184) [#189](https://github.com/toy/image_optim/pull/189) [@tgxworld](https://github.com/tgxworld) [@oblakeerickson](https://github.com/oblakeerickson) [@toy](https://github.com/toy)
8
+
9
+ ## v0.29.0 (2021-04-28)
10
+
11
+ * Require at least ruby 1.9.3 [@toy](https://github.com/toy)
12
+ * Add support for use as [pre-commit](https://pre-commit.com/) hook [#192](https://github.com/toy/image_optim/pull/192) [@proinsias](https://github.com/proinsias)
13
+ * Fix `Path#copy_metadata` by rescuing also `Errno::EACCES` as it is done in `fileutils` [#187](https://github.com/toy/image_optim/issues/187) [@toy](https://github.com/toy)
14
+ * More precise regular expression for capturing svgo version [@toy](https://github.com/toy)
15
+
16
+ ## v0.28.0 (2020-12-18)
17
+
18
+ * Fix and update list of markers in jpegoptim worker: allow to pass `com` instead of incorrect `comments` and add missing `xmp` and `none` [#188](https://github.com/toy/image_optim/issues/188) [@toy](https://github.com/toy)
19
+ * Add `--skip-if-larger` flag to pngquant worker. The pngquant worker already does this, but this will make it fail faster. [#125](https://github.com/toy/image_optim/pull/125) [#181](https://github.com/toy/image_optim/pull/181) [@iggant](https://github.com/iggant) [@oblakeerickson](https://github.com/oblakeerickson)
20
+ * Add `method` option for jpegrecompress, default to `ssim` [#102](https://github.com/toy/image_optim/issues/102) [#103](https://github.com/toy/image_optim/pull/103) [#182](https://github.com/toy/image_optim/pull/182) [@ramiroaraujo](https://github.com/ramiroaraujo) [@oblakeerickson](https://github.com/oblakeerickson)
21
+
22
+ ## v0.27.1 (2020-09-30)
23
+
24
+ * Fixed atomic replacement for case when equal `File::Stat#dev` doesn't mean that file can be linked [#180](https://github.com/toy/image_optim/issues/180) [@toy](https://github.com/toy)
25
+
26
+ ## v0.27.0 (2020-08-27)
27
+
28
+ * Use `.tmp` as the extension for temporary file if it needs to be created for atomic replacement [#178](https://github.com/toy/image_optim/issues/178) [@toy](https://github.com/toy)
29
+ * Don't create a temporary file in destination directory for atomic replacement if temporary directory is on same device as destination [#178](https://github.com/toy/image_optim/issues/178) [@toy](https://github.com/toy)
30
+
5
31
  ## v0.26.5 (2019-07-14)
6
32
 
7
33
  * Remove deprecated `rubyforge_project` attribute from gemspec [rubygems/rubygems#2436](https://github.com/rubygems/rubygems/pull/2436) [@toy](https://github.com/toy)
@@ -2,7 +2,10 @@
2
2
 
3
3
  * Create topic/feature branch: `git checkout -b awesome-changes`
4
4
  * Commit…
5
- * Add entry at the top of [ChangeLog](CHANGELOG.markdown)
5
+ * Add an entry at the top (after ## unreleased) of [ChangeLog](CHANGELOG.markdown), include:
6
+ * Issues (`[#123](https://github.com/toy/image_optim/issues/123)`)
7
+ * Pull requests (`[#123](https://github.com/toy/image_optim/pull/123)`)
8
+ * Authors (`[@octocat](https://github.com/octocat)`)
6
9
  * Run tests: `bundle exec rspec`
7
10
  * Check code style: `bundle exec rubocop`
8
11
  * Rebase on master and squash commits to logical units
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2019 Ivan Kuchin
1
+ Copyright (c) 2012-2021 Ivan Kuchin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -60,7 +60,7 @@ With version:
60
60
 
61
61
  <!---<update-version>-->
62
62
  ```ruby
63
- gem 'image_optim', '~> 0.26'
63
+ gem 'image_optim', '~> 0.30'
64
64
  ```
65
65
  <!---</update-version>-->
66
66
 
@@ -277,6 +277,10 @@ optipng:
277
277
  level: 5
278
278
  ```
279
279
 
280
+ ### Temporary directory
281
+
282
+ `image_optim` uses standard ruby library for creating temporary files. Temporary directory can be changed using one of `TMPDIR`, `TMP` or `TEMP` environment variables.
283
+
280
284
  ## Options
281
285
 
282
286
  * `:nice` — Nice level, priority of all used tools with higher value meaning lower priority, in range `-20..19`, negative values can be set only if run by root user *(defaults to `10`)*
@@ -287,6 +291,7 @@ optipng:
287
291
  * `:allow_lossy` — Allow lossy workers and optimizations *(defaults to `false`)*
288
292
  * `:cache_dir` — Configure cache directory
289
293
  * `:cache_worker_digests` - Also cache worker digests along with original file digest and worker options: updating workers invalidates cache
294
+ * `:timeout` — Maximum time in seconds to spend on one image, note multithreading and cache *(defaults to unlimited)*
290
295
 
291
296
  Worker can be disabled by passing `false` instead of options hash or by setting option `:disable` to `true`.
292
297
 
@@ -306,12 +311,13 @@ Worker has no options
306
311
 
307
312
  ### jpegoptim:
308
313
  * `:allow_lossy` — Allow limiting maximum quality *(defaults to `false`)*
309
- * `:strip` — List of extra markers to strip: `:comments`, `:exif`, `:iptc`, `:icc` or `:all` *(defaults to `:all`)*
314
+ * `:strip` — List of markers to strip: `:com`, `:exif`, `:iptc`, `:icc`, `:xmp`, `:none` or `:all` *(defaults to `:all`)*
310
315
  * `:max_quality` — Maximum image quality factor `0`..`100`, ignored in default/lossless mode *(defaults to `100`)*
311
316
 
312
317
  ### jpegrecompress:
313
318
  * `:allow_lossy` — Allow worker, it is always lossy *(defaults to `false`)*
314
319
  * `:quality` — JPEG quality preset: `0` - low, `1` - medium, `2` - high, `3` - veryhigh *(defaults to `3`)*
320
+ * `:method` — Comparison Metric: `mpe` - Mean pixel error, `ssim` - Structural similarity, `ms-ssim` - Multi-scale structural similarity (slow!), `smallfry` - Linear-weighted BBCQ-like (may be patented) *(defaults to ssim)*
315
321
 
316
322
  ### jpegtran:
317
323
  * `:copy_chunks` — Copy all chunks *(defaults to `false`)*
@@ -357,4 +363,4 @@ In separate file [CHANGELOG.markdown](CHANGELOG.markdown).
357
363
 
358
364
  ## Copyright
359
365
 
360
- Copyright (c) 2012-2019 Ivan Kuchin. See [LICENSE.txt](LICENSE.txt) for details.
366
+ Copyright (c) 2012-2021 Ivan Kuchin. See [LICENSE.txt](LICENSE.txt) for details.
data/Vagrantfile CHANGED
@@ -3,7 +3,7 @@
3
3
  Vagrant.configure('2') do |config|
4
4
  config.vm.box = 'ubuntu/precise64'
5
5
 
6
- config.vm.provision 'shell', :inline => <<-SH
6
+ config.vm.provision 'shell', inline: <<-SH
7
7
  set -e
8
8
 
9
9
  cd /vagrant
data/image_optim.gemspec CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'image_optim'
5
- s.version = '0.26.5'
5
+ s.version = '0.30.0'
6
6
  s.summary = %q{Command line tool and ruby interface to optimize (lossless compress, optionally lossy) jpeg, png, gif and svg images using external utilities (advpng, gifsicle, jhead, jpeg-recompress, jpegoptim, jpegrescan, jpegtran, optipng, pngcrush, pngout, pngquant, svgo)}
7
- s.homepage = "http://github.com/toy/#{s.name}"
7
+ s.homepage = "https://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
9
9
  s.license = 'MIT'
10
10
 
11
+ s.required_ruby_version = '>= 1.9.3'
12
+
11
13
  s.metadata = {
12
14
  'bug_tracker_uri' => "https://github.com/toy/#{s.name}/issues",
13
15
  'changelog_uri' => "https://github.com/toy/#{s.name}/blob/master/CHANGELOG.markdown",
@@ -33,7 +35,8 @@ EOF
33
35
 
34
36
  s.add_development_dependency 'image_optim_pack', '~> 0.2', '>= 0.2.2'
35
37
  s.add_development_dependency 'rspec', '~> 3.0'
36
- if RUBY_VERSION >= '2.2' && !Gem.win_platform? && !defined?(JRUBY_VERSION)
37
- s.add_development_dependency 'rubocop', '~> 0.59'
38
+ if RUBY_VERSION >= '2.4' && !Gem.win_platform? && !defined?(JRUBY_VERSION)
39
+ s.add_development_dependency 'rubocop', '~> 1.0'
40
+ s.add_development_dependency 'rubocop-rspec', '~> 2.0'
38
41
  end
39
42
  end
data/lib/image_optim.rb CHANGED
@@ -3,10 +3,12 @@
3
3
  require 'image_optim/bin_resolver'
4
4
  require 'image_optim/cache'
5
5
  require 'image_optim/config'
6
+ require 'image_optim/errors'
6
7
  require 'image_optim/handler'
7
8
  require 'image_optim/image_meta'
8
9
  require 'image_optim/optimized_path'
9
10
  require 'image_optim/path'
11
+ require 'image_optim/timer'
10
12
  require 'image_optim/worker'
11
13
  require 'in_threads'
12
14
  require 'shellwords'
@@ -46,6 +48,9 @@ class ImageOptim
46
48
  # Cache worker digests
47
49
  attr_reader :cache_worker_digests
48
50
 
51
+ # Timeout in seconds for each image
52
+ attr_reader :timeout
53
+
49
54
  # Initialize workers, specify options using worker underscored name:
50
55
  #
51
56
  # pass false to disable worker
@@ -78,6 +83,7 @@ class ImageOptim
78
83
  allow_lossy
79
84
  cache_dir
80
85
  cache_worker_digests
86
+ timeout
81
87
  ].each do |name|
82
88
  instance_variable_set(:"@#{name}", config.send(name))
83
89
  $stderr << "#{name}: #{send(name)}\n" if verbose
@@ -110,11 +116,17 @@ class ImageOptim
110
116
  return unless (workers = workers_for_image(original))
111
117
 
112
118
  optimized = @cache.fetch(original) do
119
+ timer = timeout && Timer.new(timeout)
120
+
113
121
  Handler.for(original) do |handler|
114
- workers.each do |worker|
115
- handler.process do |src, dst|
116
- worker.optimize(src, dst)
122
+ begin
123
+ workers.each do |worker|
124
+ handler.process do |src, dst|
125
+ worker.optimize(src, dst, timeout: timer)
126
+ end
117
127
  end
128
+ rescue Errors::TimeoutExceeded
129
+ handler.result
118
130
  end
119
131
  end
120
132
  end
@@ -188,12 +200,6 @@ class ImageOptim
188
200
  optimize_image_method?(method) || super
189
201
  end
190
202
 
191
- if RUBY_VERSION < '1.9'
192
- def respond_to?(method, include_private = false)
193
- optimize_image_method?(method) || super
194
- end
195
- end
196
-
197
203
  # Version of image_optim gem spec loaded
198
204
  def version
199
205
  Gem.loaded_specs['image_optim'].version.to_s
@@ -14,9 +14,11 @@ class ImageOptim
14
14
  # Holds bin name and path, gets version
15
15
  class Bin
16
16
  class UnknownVersion < Error; end
17
+
17
18
  class BadVersion < Error; end
18
19
 
19
20
  attr_reader :name, :path, :version
21
+
20
22
  def initialize(name, path)
21
23
  @name = name.to_sym
22
24
  @path = path.to_s
@@ -36,30 +38,30 @@ class ImageOptim
36
38
  is = ComparableCondition.is
37
39
 
38
40
  FAIL_CHECKS = {
39
- :pngcrush => [
41
+ pngcrush: [
40
42
  [is.between?('1.7.60', '1.7.65'), 'is known to produce broken pngs'],
41
43
  [is == '1.7.80', 'loses one color in indexed images'],
42
44
  ],
43
- :pngquant => [
45
+ pngquant: [
44
46
  [is < '2.0', 'is not supported'],
45
47
  ],
46
48
  }.freeze
47
49
 
48
50
  WARN_CHECKS = {
49
- :advpng => [
51
+ advpng: [
50
52
  [is == 'none', 'is of unknown version'],
51
53
  [is < '1.17', 'does not use zopfli'],
52
54
  ],
53
- :gifsicle => [
55
+ gifsicle: [
54
56
  [is < '1.85', 'does not support removing extension blocks'],
55
57
  ],
56
- :pngcrush => [
58
+ pngcrush: [
57
59
  [is < '1.7.38', 'does not have blacken flag'],
58
60
  ],
59
- :pngquant => [
61
+ pngquant: [
60
62
  [is < '2.1', 'may be lossy even with quality `100-`'],
61
63
  ],
62
- :optipng => [
64
+ optipng: [
63
65
  [is < '0.7', 'does not support -strip option'],
64
66
  ],
65
67
  }.freeze
@@ -110,7 +112,7 @@ class ImageOptim
110
112
  when :gifsicle, :jpegoptim, :optipng
111
113
  capture("#{escaped_path} --version 2> #{Path::NULL}")[/\d+(\.\d+)+/]
112
114
  when :svgo, :pngquant
113
- capture("#{escaped_path} --version 2>&1")[/\d+(\.\d+)+/]
115
+ capture("#{escaped_path} --version 2>&1")[/\A\d+(\.\d+)+/]
114
116
  when :jhead, :'jpeg-recompress'
115
117
  capture("#{escaped_path} -V 2> #{Path::NULL}")[/\d+(\.\d+)+/]
116
118
  when :jpegtran