image_optim 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/image_optim +8 -2
- data/image_optim.gemspec +1 -1
- data/lib/image_optim.rb +4 -1
- data/lib/image_optim/option_helpers.rb +1 -1
- data/lib/image_optim/worker.rb +1 -1
- metadata +4 -4
data/bin/image_optim
CHANGED
@@ -55,7 +55,11 @@ end
|
|
55
55
|
if ARGV.empty?
|
56
56
|
abort "specify image paths to optimize\n\n#{option_parser.help}"
|
57
57
|
else
|
58
|
-
io =
|
58
|
+
io = begin
|
59
|
+
ImageOptim.new(options)
|
60
|
+
rescue ImageOptim::ConfigurationError, ImageOptim::BinaryNotFoundError => e
|
61
|
+
abort e
|
62
|
+
end
|
59
63
|
paths = ARGV.reject do |arg|
|
60
64
|
unless File.file?(arg)
|
61
65
|
$stderr << "WARN: #{arg} is not a file\n"
|
@@ -112,5 +116,7 @@ else
|
|
112
116
|
end
|
113
117
|
end
|
114
118
|
lines, src_sizes, dst_sizes = results.transpose
|
115
|
-
|
119
|
+
if lines
|
120
|
+
$stdout.puts lines, "Total: #{size_percent(src_sizes.inject(:+), dst_sizes.inject(:+))}\n"
|
121
|
+
end
|
116
122
|
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.5.
|
5
|
+
s.version = '0.5.1'
|
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
@@ -6,6 +6,9 @@ class ImageOptim
|
|
6
6
|
autoload :Util, 'image_optim/util'
|
7
7
|
autoload :Worker, 'image_optim/worker'
|
8
8
|
|
9
|
+
class ConfigurationError < StandardError; end
|
10
|
+
class BinaryNotFoundError < StandardError; end
|
11
|
+
|
9
12
|
include OptionHelpers
|
10
13
|
|
11
14
|
# Hash of initialized workers by format they apply to
|
@@ -69,7 +72,7 @@ class ImageOptim
|
|
69
72
|
when String
|
70
73
|
worker_options = {:bin => worker_options}
|
71
74
|
else
|
72
|
-
raise "Got #{worker_options.inspect} for #{klass.name} options"
|
75
|
+
raise ConfigurationError, "Got #{worker_options.inspect} for #{klass.name} options"
|
73
76
|
end
|
74
77
|
worker = klass.new({:nice => nice, :verbose => verbose}.merge(worker_options))
|
75
78
|
klass.image_formats.each do |format|
|
@@ -26,7 +26,7 @@ class ImageOptim
|
|
26
26
|
# Raise unless all options are deleted
|
27
27
|
def assert_options_empty!(options)
|
28
28
|
unless options.empty?
|
29
|
-
raise "unknown options #{options.inspect} for #{self}"
|
29
|
+
raise ConfigurationError, "unknown options #{options.inspect} for #{self}"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/image_optim/worker.rb
CHANGED
@@ -45,7 +45,7 @@ class ImageOptim
|
|
45
45
|
get_option!(options, :nice, 10){ |v| v.to_i }
|
46
46
|
get_option!(options, :verbose, false)
|
47
47
|
parse_options(options)
|
48
|
-
raise "`#{bin}` not found" if `which #{bin.to_s.shellescape}`.empty?
|
48
|
+
raise BinaryNotFoundError, "`#{bin}` not found" if `which #{bin.to_s.shellescape}`.empty?
|
49
49
|
assert_options_empty!(options)
|
50
50
|
end
|
51
51
|
|
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:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
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-
|
18
|
+
date: 2012-08-06 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: fspath
|