image-optimizer 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/image-optimizer.gemspec +2 -2
- data/lib/image-optimizer.rb +9 -0
- data/lib/image-optimizer/jpeg.rb +6 -3
- data/lib/image-optimizer/png.rb +11 -8
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/image-optimizer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "image-optimizer"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Martin Koz\u{e1}k"]
|
12
|
-
s.date = "2012-08-
|
12
|
+
s.date = "2012-08-06"
|
13
13
|
s.email = "martinkozak@martinkozak.net"
|
14
14
|
s.executables = ["image-optimizer"]
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/image-optimizer.rb
CHANGED
@@ -9,28 +9,36 @@ module ImageOptimizer
|
|
9
9
|
|
10
10
|
##
|
11
11
|
# Indicates, callback is called before the optimization.
|
12
|
+
#
|
12
13
|
# @var [Symbol]
|
14
|
+
# @since 0.2
|
13
15
|
#
|
14
16
|
|
15
17
|
BEFORE = :before
|
16
18
|
|
17
19
|
##
|
18
20
|
# Indicates, callback is called before the optimization.
|
21
|
+
#
|
19
22
|
# @var [Symbol]
|
23
|
+
# @since 0.2
|
20
24
|
#
|
21
25
|
|
22
26
|
AFTER = :after
|
23
27
|
|
24
28
|
##
|
25
29
|
# Indicates, callback returns the method.
|
30
|
+
#
|
26
31
|
# @var [Symbol]
|
32
|
+
# @since 0.2
|
27
33
|
#
|
28
34
|
|
29
35
|
METHOD = :method
|
30
36
|
|
31
37
|
##
|
32
38
|
# Optimizers availiability cache.
|
39
|
+
#
|
33
40
|
# @var [Hash]
|
41
|
+
# @since 0.2
|
34
42
|
#
|
35
43
|
|
36
44
|
@optimizers
|
@@ -103,6 +111,7 @@ module ImageOptimizer
|
|
103
111
|
#
|
104
112
|
# @param [Symbol, String] command command name
|
105
113
|
# @return [Boolean]
|
114
|
+
# @since 0.2
|
106
115
|
#
|
107
116
|
|
108
117
|
def self.available?(command)
|
data/lib/image-optimizer/jpeg.rb
CHANGED
@@ -1,28 +1,31 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# (c) 2012 Martin Kozák (martinkozak@martinkozak.net)
|
3
3
|
|
4
|
+
require "shellwords"
|
5
|
+
|
4
6
|
module ImageOptimizer
|
5
7
|
|
6
8
|
##
|
7
9
|
# JPEG optimizing module.
|
8
|
-
# @since
|
10
|
+
# @since 0.2
|
9
11
|
#
|
10
12
|
|
11
13
|
module Jpeg
|
12
14
|
|
13
15
|
def self.optimize(path, &block)
|
16
|
+
path_escaped = Shellwords::escape(path)
|
14
17
|
|
15
18
|
# calls back
|
16
19
|
block.call(path.dup, ImageOptimizer::BEFORE)
|
17
20
|
|
18
21
|
if ImageOptimizer.available? :jpegoptim
|
19
22
|
block.call(:jpegoptim, ImageOptimizer::METHOD)
|
20
|
-
`jpegoptim --strip-all #{
|
23
|
+
`jpegoptim --strip-all #{path_escaped} 2> /dev/null`
|
21
24
|
end
|
22
25
|
|
23
26
|
if ImageOptimizer.available? :jpegtran
|
24
27
|
block.call(:jpegtran, ImageOptimizer::METHOD)
|
25
|
-
`jpegtran -arithmetic -optimize -progressive -copy none #{
|
28
|
+
`jpegtran -arithmetic -optimize -progressive -copy none #{path_escaped} 2> /dev/null`
|
26
29
|
end
|
27
30
|
|
28
31
|
# calls back
|
data/lib/image-optimizer/png.rb
CHANGED
@@ -4,17 +4,19 @@
|
|
4
4
|
require "hash-utils"
|
5
5
|
require "fileutils"
|
6
6
|
require "tmpdir"
|
7
|
+
require "shellwords"
|
7
8
|
|
8
9
|
module ImageOptimizer
|
9
10
|
|
10
11
|
##
|
11
12
|
# PNG optimizing module.
|
12
|
-
# @since
|
13
|
+
# @since 0.2
|
13
14
|
#
|
14
15
|
|
15
16
|
module Png
|
16
17
|
|
17
18
|
def self.optimize(path, &block)
|
19
|
+
path_escaped = Shellwords::escape(path)
|
18
20
|
|
19
21
|
# calls back
|
20
22
|
block.call(path.dup, ImageOptimizer::BEFORE)
|
@@ -41,7 +43,7 @@ module ImageOptimizer
|
|
41
43
|
|
42
44
|
# xcf2png
|
43
45
|
block.call(:xcf2png, ImageOptimizer::METHOD)
|
44
|
-
`xcf2png #{xcf_path} > #{png_path} 2> /dev/null`
|
46
|
+
`xcf2png #{Shellwords::escape(xcf_path)} > #{Shellwords::escape(png_path)} 2> /dev/null`
|
45
47
|
FileUtils.rm(xcf_path)
|
46
48
|
|
47
49
|
if protect
|
@@ -51,16 +53,17 @@ module ImageOptimizer
|
|
51
53
|
# Old method (ImageMagick)
|
52
54
|
elsif ImageOptimizer.available? :convert
|
53
55
|
block.call(:convert, ImageOptimizer::METHOD)
|
54
|
-
`convert #{
|
56
|
+
`convert #{path_escaped} -quality 100 #{path_escaped} 2> /dev/null`
|
55
57
|
end
|
56
58
|
|
57
59
|
# General optimizers
|
58
|
-
if ImageOptimizer.available? :
|
59
|
-
block.call(:pngcrush, ImageOptimizer::METHOD)
|
60
|
-
`pngcrush -reduce -brute -ow #{path} 2> /dev/null`
|
61
|
-
elsif ImageOptimizer.available? :optipng
|
60
|
+
if ImageOptimizer.available? :optipng
|
62
61
|
block.call(:optipng, ImageOptimizer::METHOD)
|
63
|
-
`optipng -o 7 #{
|
62
|
+
`optipng -o 7 #{path_escaped} 2> /dev/null`
|
63
|
+
elsif ImageOptimizer.available? :pngcrush
|
64
|
+
block.call(:pngcrush, ImageOptimizer::METHOD)
|
65
|
+
`pngcrush -reduce -brute -ow #{path_escaped} 2> /dev/null`
|
66
|
+
|
64
67
|
end
|
65
68
|
|
66
69
|
# calls back
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image-optimizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yaop
|
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
segments:
|
130
130
|
- 0
|
131
|
-
hash:
|
131
|
+
hash: 4132611269577949455
|
132
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
133
|
none: false
|
134
134
|
requirements:
|