image_optim 0.4.2 → 0.5.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
@@ -31,12 +31,16 @@ Usege:
31
31
  end
32
32
  end
33
33
 
34
+ op.on('-v', '--verbose', 'Verbose info') do |verbose|
35
+ options[:verbose] = verbose
36
+ end
37
+
34
38
  op.on_tail('-h', '--help', 'Show full help') do
35
39
  puts option_parser.help
36
40
  exit
37
41
  end
38
42
 
39
- op.on_tail('-v', '--version', 'Show version') do
43
+ op.on_tail('--version', 'Show version') do
40
44
  puts ImageOptim.version
41
45
  exit
42
46
  end
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.4.2'
5
+ s.version = '0.5.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
@@ -56,6 +56,8 @@ class ImageOptim
56
56
  end
57
57
  @threads = limit_with_range(threads, 1..16)
58
58
 
59
+ verbose = options.delete(:verbose)
60
+
59
61
  @workers_by_format = {}
60
62
  Worker.klasses.each do |klass|
61
63
  case worker_options = options.delete(klass.underscored_name.to_sym)
@@ -69,7 +71,7 @@ class ImageOptim
69
71
  else
70
72
  raise "Got #{worker_options.inspect} for #{klass.name} options"
71
73
  end
72
- worker = klass.new({:nice => nice}.merge(worker_options))
74
+ worker = klass.new({:nice => nice, :verbose => verbose}.merge(worker_options))
73
75
  klass.image_formats.each do |format|
74
76
  @workers_by_format[format] ||= []
75
77
  @workers_by_format[format] << worker
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'shellwords'
2
4
  require 'image_optim'
3
5
 
@@ -34,10 +36,14 @@ class ImageOptim
34
36
  # Binary name or path
35
37
  attr_reader :nice
36
38
 
39
+ # Be verbose
40
+ attr_reader :verbose
41
+
37
42
  # Configure (raises on extra options), find binary (raises if not found)
38
43
  def initialize(options = {})
39
44
  get_option!(options, :bin, default_bin)
40
45
  get_option!(options, :nice, 10){ |v| v.to_i }
46
+ get_option!(options, :verbose, false)
41
47
  parse_options(options)
42
48
  raise "`#{bin}` not found" if `which #{bin.to_s.shellescape}`.empty?
43
49
  assert_options_empty!(options)
@@ -54,17 +60,24 @@ class ImageOptim
54
60
 
55
61
  # Optimize file from src to dst, return boolean representing success status
56
62
  def optimize(src, dst)
63
+ command = [bin, *command_args(src, dst)].map(&:to_s).shelljoin
64
+ start = Time.now
57
65
  pid = fork do
58
66
  $stdout.reopen('/dev/null', 'w')
59
67
  $stderr.reopen('/dev/null', 'w')
60
68
  Process.setpriority(Process::PRIO_PROCESS, 0, nice)
61
- exec bin, *command_args(src, dst)
69
+ exec command
62
70
  end
63
71
  Process.wait pid
72
+ duration = Time.now - start
64
73
  if $?.signaled?
65
74
  raise SignalException.new($?.termsig)
66
75
  end
67
- $?.success? && dst.size? && dst.size < src.size
76
+ success = $?.success? && dst.size? && dst.size < src.size
77
+ if verbose
78
+ print "#{success ? '✓' : '✗'} #{duration}s #{command}\n"
79
+ end
80
+ success
68
81
  end
69
82
 
70
83
  # Name of binary determined from class name
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 2
10
- version: 0.4.2
8
+ - 5
9
+ - 0
10
+ version: 0.5.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-02-26 00:00:00 Z
18
+ date: 2012-08-05 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: fspath
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  requirements: []
160
160
 
161
161
  rubyforge_project: image_optim
162
- rubygems_version: 1.8.17
162
+ rubygems_version: 1.8.24
163
163
  signing_key:
164
164
  specification_version: 3
165
165
  summary: Optimize (lossless compress) images (jpeg, png, gif) using external utilities (advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout)
@@ -173,4 +173,3 @@ test_files:
173
173
  - spec/images/transparency1.png
174
174
  - spec/images/transparency2.png
175
175
  - spec/images/vergroessert.jpg
176
- has_rdoc: