image_optim 0.5.1 → 0.6.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.
data/bin/image_optim CHANGED
@@ -4,6 +4,7 @@
4
4
  require 'image_optim'
5
5
  require 'progress'
6
6
  require 'optparse'
7
+ require 'find'
7
8
 
8
9
  options = {}
9
10
 
@@ -20,7 +21,7 @@ Usege:
20
21
  options[:threads] = threads
21
22
  end
22
23
 
23
- op.on('--[no-]nice NUMBER', Integer, 'Nice levle (defaults to 10)') do |nice|
24
+ op.on('--[no-]nice NUMBER', Integer, 'Nice level (defaults to 10)') do |nice|
24
25
  options[:nice] = nice
25
26
  end
26
27
 
@@ -31,6 +32,10 @@ Usege:
31
32
  end
32
33
  end
33
34
 
35
+ op.on('-r', '-R', '--recursive', 'Scan directories') do |recursive|
36
+ options[:recursive] = recursive
37
+ end
38
+
34
39
  op.on('-v', '--verbose', 'Verbose info') do |verbose|
35
40
  options[:verbose] = verbose
36
41
  end
@@ -55,14 +60,29 @@ end
55
60
  if ARGV.empty?
56
61
  abort "specify image paths to optimize\n\n#{option_parser.help}"
57
62
  else
63
+ recursive = options.delete(:recursive)
58
64
  io = begin
59
65
  ImageOptim.new(options)
60
66
  rescue ImageOptim::ConfigurationError, ImageOptim::BinaryNotFoundError => e
61
67
  abort e
62
68
  end
63
- paths = ARGV.reject do |arg|
64
- unless File.file?(arg)
65
- $stderr << "WARN: #{arg} is not a file\n"
69
+
70
+ paths = []
71
+ ARGV.each do |arg|
72
+ if File.file?(arg)
73
+ if io.optimizable?(arg)
74
+ paths << arg
75
+ else
76
+ warn "#{arg} is not an image or there is no optimizer for it"
77
+ end
78
+ else
79
+ if recursive
80
+ Find.find(arg) do |path|
81
+ paths << path if File.file?(path) && io.optimizable?(path)
82
+ end
83
+ else
84
+ warn "#{arg} is not a file"
85
+ end
66
86
  end
67
87
  end
68
88
  paths = paths.with_progress('optimizing') if paths.length > 1
data/image_optim.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'image_optim'
5
- s.version = '0.5.1'
5
+ s.version = '0.6.0'
6
6
  s.summary = %q{Optimize (lossless compress) images (jpeg, png, gif) using external utilities (advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout)}
7
7
  s.homepage = "http://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
data/lib/image_optim.rb CHANGED
@@ -149,6 +149,10 @@ class ImageOptim
149
149
  Gem.loaded_specs['image_optim'].version.to_s rescue nil
150
150
  end
151
151
 
152
+ def optimizable?(path)
153
+ !!workers_for_image(path)
154
+ end
155
+
152
156
  private
153
157
 
154
158
  def run_method_for(paths, method_name, &block)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_optim
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 1
10
- version: 0.5.1
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ivan Kuchin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-06 00:00:00 Z
18
+ date: 2012-11-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: fspath
@@ -173,3 +173,4 @@ test_files:
173
173
  - spec/images/transparency1.png
174
174
  - spec/images/transparency2.png
175
175
  - spec/images/vergroessert.jpg
176
+ has_rdoc: