smusher 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +11 -0
- data/Gemfile.lock +30 -0
- data/Rakefile +7 -9
- data/Readme.md +4 -4
- data/VERSION +1 -1
- data/bin/smusher +2 -0
- data/lib/smusher.rb +29 -15
- data/smusher.gemspec +36 -37
- data/spec/smusher_spec.rb +2 -2
- metadata +30 -18
- data/.gitignore +0 -2
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
httpclient (2.1.5.2)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
json (1.4.6)
|
12
|
+
rake (0.8.7)
|
13
|
+
rspec (2.4.0)
|
14
|
+
rspec-core (~> 2.4.0)
|
15
|
+
rspec-expectations (~> 2.4.0)
|
16
|
+
rspec-mocks (~> 2.4.0)
|
17
|
+
rspec-core (2.4.0)
|
18
|
+
rspec-expectations (2.4.0)
|
19
|
+
diff-lcs (~> 1.1.2)
|
20
|
+
rspec-mocks (2.4.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
httpclient
|
27
|
+
jeweler
|
28
|
+
json
|
29
|
+
rake
|
30
|
+
rspec (~> 2)
|
data/Rakefile
CHANGED
@@ -1,20 +1,18 @@
|
|
1
|
-
task :default
|
2
|
-
|
3
|
-
|
1
|
+
task :default do
|
2
|
+
sh "rspec spec/"
|
3
|
+
end
|
4
4
|
|
5
5
|
begin
|
6
6
|
require 'jeweler'
|
7
|
-
project_name = 'smusher'
|
8
7
|
Jeweler::Tasks.new do |gem|
|
9
|
-
gem.name =
|
8
|
+
gem.name = 'smusher'
|
10
9
|
gem.summary = "Automatic Lossless Reduction Of All Your Images"
|
11
|
-
gem.email = "
|
12
|
-
gem.homepage = "http://github.com/grosser/#{
|
10
|
+
gem.email = "michael@grosser.it"
|
11
|
+
gem.homepage = "http://github.com/grosser/#{gem.name}"
|
13
12
|
gem.authors = ["Michael Grosser"]
|
14
|
-
%w[rake json httpclient].each{|d| gem.add_dependency d}
|
15
13
|
end
|
16
14
|
|
17
15
|
Jeweler::GemcutterTasks.new
|
18
16
|
rescue LoadError
|
19
17
|
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
20
|
-
end
|
18
|
+
end
|
data/Readme.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
*LOSSLESS* image size reduction for jpg, png and gif in the cloud
|
2
2
|
|
3
3
|
- no image libraries needed, everything done in the interwebs
|
4
|
-
- less size (up 97% saving) = faster downloads = less bandwidth + happy users
|
4
|
+
- less size (up 97% saving) = faster downloads = less bandwidth + happy users
|
5
5
|
|
6
6
|
Install
|
7
7
|
=======
|
@@ -58,11 +58,11 @@ reduce images and minify css + js -> try [reduce](http://github.com/grosser/redu
|
|
58
58
|
|
59
59
|
Authors
|
60
60
|
======
|
61
|
-
###Contributors
|
61
|
+
### [Contributors](http://github.com/grosser/smusher/contributors)
|
62
62
|
- [ahaller](http://ahax.de/)
|
63
63
|
- [retr0h](http://geminstallthat.wordpress.com/)
|
64
64
|
- [Nate Pickens](http://github.com/npickens)
|
65
65
|
|
66
|
-
[Michael Grosser](http://
|
67
|
-
|
66
|
+
[Michael Grosser](http://grosser.it)<br/>
|
67
|
+
michael@grosser.it<br/>
|
68
68
|
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.7
|
data/bin/smusher
CHANGED
data/lib/smusher.rb
CHANGED
@@ -25,7 +25,7 @@ module Smusher
|
|
25
25
|
check_options(options)
|
26
26
|
puts "THIS FILE IS EMPTY!!! #{file}" and return if size(file).zero?
|
27
27
|
|
28
|
-
with_logging(file,options[:quiet]) do
|
28
|
+
with_logging(file, options[:quiet]) do
|
29
29
|
write_optimized_data(file, service)
|
30
30
|
end
|
31
31
|
end
|
@@ -43,7 +43,7 @@ module Smusher
|
|
43
43
|
|
44
44
|
def check_options(options)
|
45
45
|
known_options = [:convert_gifs, :quiet, :service]
|
46
|
-
if options.detect{|k,
|
46
|
+
if options.detect{|k,_| not known_options.include?(k)}
|
47
47
|
raise "Known options: #{known_options*' '}"
|
48
48
|
end
|
49
49
|
end
|
@@ -55,22 +55,26 @@ module Smusher
|
|
55
55
|
raise "Error: empty file downloaded" if optimized.size < MINIMUM_IMAGE_SIZE
|
56
56
|
raise "cannot be optimized further" if size(file) == optimized.size
|
57
57
|
|
58
|
-
File.open(file,'wb') {|f| f.write optimized}
|
58
|
+
File.open(file,'wb') {|f| f.write optimized }
|
59
59
|
|
60
60
|
if service.converts_gif_to_png? && File.extname(file) == ".gif" && optimized[0..2] != "GIF"
|
61
|
-
|
61
|
+
result_file = file.sub(/\.gif$/, '.png')
|
62
|
+
`mv #{file} #{result_file}`
|
63
|
+
result_file
|
64
|
+
else
|
65
|
+
file
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
65
69
|
def sanitize_folder(folder)
|
66
|
-
folder.sub(%r[/$],'')#remove tailing slash
|
70
|
+
folder.sub(%r[/$],'') # remove tailing slash
|
67
71
|
end
|
68
72
|
|
69
|
-
def images_in_folder(folder,with_gifs=false)
|
73
|
+
def images_in_folder(folder, with_gifs=false)
|
70
74
|
folder = sanitize_folder(folder)
|
71
75
|
images = %w[png jpg jpeg JPG]
|
72
76
|
images << 'gif' if with_gifs
|
73
|
-
images.map! {|ext| "#{folder}/**/*.#{ext}"}
|
77
|
+
images.map! {|ext| "#{folder}/**/*.#{ext}" }
|
74
78
|
FileList[*images]
|
75
79
|
end
|
76
80
|
|
@@ -78,17 +82,27 @@ module Smusher
|
|
78
82
|
File.exist?(file) ? File.size(file) : 0
|
79
83
|
end
|
80
84
|
|
81
|
-
def with_logging(file,quiet)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
def with_logging(file, quiet)
|
86
|
+
if quiet
|
87
|
+
yield rescue nil
|
88
|
+
else
|
89
|
+
puts "smushing #{file}"
|
90
|
+
|
91
|
+
before = size(file)
|
92
|
+
|
93
|
+
# notify user about changed file
|
94
|
+
begin
|
95
|
+
result_file = yield
|
96
|
+
puts "--> #{result_file}" if file != result_file
|
97
|
+
file = result_file
|
98
|
+
rescue
|
99
|
+
puts $!
|
100
|
+
end
|
87
101
|
|
88
|
-
|
102
|
+
after = size(file)
|
89
103
|
result = "#{(100*after)/before}%"
|
90
104
|
puts "#{before} -> #{after}".ljust(40) + " = #{result}"
|
91
105
|
puts ''
|
92
106
|
end
|
93
107
|
end
|
94
|
-
end
|
108
|
+
end
|
data/smusher.gemspec
CHANGED
@@ -1,63 +1,62 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{smusher}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-03-15}
|
13
13
|
s.default_executable = %q{smusher}
|
14
|
-
s.email = %q{
|
14
|
+
s.email = %q{michael@grosser.it}
|
15
15
|
s.executables = ["smusher"]
|
16
16
|
s.files = [
|
17
|
-
"
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
17
|
+
"Gemfile",
|
18
|
+
"Gemfile.lock",
|
19
|
+
"Rakefile",
|
20
|
+
"Readme.md",
|
21
|
+
"VERSION",
|
22
|
+
"bin/smusher",
|
23
|
+
"lib/smusher.rb",
|
24
|
+
"lib/smusher/puny_png.rb",
|
25
|
+
"lib/smusher/smush_it.rb",
|
26
|
+
"smusher.gemspec",
|
27
|
+
"spec/empty/.gitignore",
|
28
|
+
"spec/images/ad.gif",
|
29
|
+
"spec/images/add.png",
|
30
|
+
"spec/images/drink_empty.png",
|
31
|
+
"spec/images/logo.gif",
|
32
|
+
"spec/images/people.jpg",
|
33
|
+
"spec/images/water.JPG",
|
34
|
+
"spec/images/woman.jpeg",
|
35
|
+
"spec/out/ad.gif",
|
36
|
+
"spec/out/people.jpg",
|
37
|
+
"spec/reduced/add.png",
|
38
|
+
"spec/reduced/add_puny.png",
|
39
|
+
"spec/reduced/fam.png",
|
40
|
+
"spec/smusher/puny_png_spec.rb",
|
41
|
+
"spec/smusher/smush_it_spec.rb",
|
42
|
+
"spec/smusher_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
43
44
|
]
|
44
45
|
s.homepage = %q{http://github.com/grosser/smusher}
|
45
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
46
46
|
s.require_paths = ["lib"]
|
47
|
-
s.rubygems_version = %q{1.
|
47
|
+
s.rubygems_version = %q{1.4.2}
|
48
48
|
s.summary = %q{Automatic Lossless Reduction Of All Your Images}
|
49
49
|
s.test_files = [
|
50
50
|
"spec/smusher/puny_png_spec.rb",
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
"spec/smusher/smush_it_spec.rb",
|
52
|
+
"spec/smusher_spec.rb",
|
53
|
+
"spec/spec_helper.rb"
|
54
54
|
]
|
55
55
|
|
56
56
|
if s.respond_to? :specification_version then
|
57
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
58
57
|
s.specification_version = 3
|
59
58
|
|
60
|
-
if Gem::Version.new(Gem::
|
59
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
61
60
|
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
62
61
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
63
62
|
s.add_runtime_dependency(%q<httpclient>, [">= 0"])
|
data/spec/smusher_spec.rb
CHANGED
@@ -170,7 +170,7 @@ describe :smusher do
|
|
170
170
|
describe :logging do
|
171
171
|
it "yields" do
|
172
172
|
val = 0
|
173
|
-
Smusher.send(:with_logging
|
173
|
+
Smusher.send(:with_logging, @file, false) {val = 1; @file}
|
174
174
|
val.should == 1
|
175
175
|
end
|
176
176
|
end
|
@@ -178,4 +178,4 @@ describe :smusher do
|
|
178
178
|
it "has a VERSION" do
|
179
179
|
Smusher::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
180
180
|
end
|
181
|
-
end
|
181
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 1
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
9
|
+
- 7
|
10
|
+
version: 0.4.7
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Michael Grosser
|
@@ -14,47 +15,53 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-03-15 00:00:00 +01:00
|
18
19
|
default_executable: smusher
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
|
-
name: rake
|
22
|
-
prerelease: false
|
23
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
27
28
|
segments:
|
28
29
|
- 0
|
29
30
|
version: "0"
|
30
|
-
|
31
|
+
prerelease: false
|
31
32
|
version_requirements: *id001
|
33
|
+
type: :runtime
|
34
|
+
name: rake
|
32
35
|
- !ruby/object:Gem::Dependency
|
33
|
-
name: json
|
34
|
-
prerelease: false
|
35
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
36
38
|
requirements:
|
37
39
|
- - ">="
|
38
40
|
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
39
42
|
segments:
|
40
43
|
- 0
|
41
44
|
version: "0"
|
42
|
-
|
45
|
+
prerelease: false
|
43
46
|
version_requirements: *id002
|
47
|
+
type: :runtime
|
48
|
+
name: json
|
44
49
|
- !ruby/object:Gem::Dependency
|
45
|
-
name: httpclient
|
46
|
-
prerelease: false
|
47
50
|
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
48
52
|
requirements:
|
49
53
|
- - ">="
|
50
54
|
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
51
56
|
segments:
|
52
57
|
- 0
|
53
58
|
version: "0"
|
54
|
-
|
59
|
+
prerelease: false
|
55
60
|
version_requirements: *id003
|
61
|
+
type: :runtime
|
62
|
+
name: httpclient
|
56
63
|
description:
|
57
|
-
email:
|
64
|
+
email: michael@grosser.it
|
58
65
|
executables:
|
59
66
|
- smusher
|
60
67
|
extensions: []
|
@@ -62,7 +69,8 @@ extensions: []
|
|
62
69
|
extra_rdoc_files: []
|
63
70
|
|
64
71
|
files:
|
65
|
-
-
|
72
|
+
- Gemfile
|
73
|
+
- Gemfile.lock
|
66
74
|
- Rakefile
|
67
75
|
- Readme.md
|
68
76
|
- VERSION
|
@@ -93,28 +101,32 @@ homepage: http://github.com/grosser/smusher
|
|
93
101
|
licenses: []
|
94
102
|
|
95
103
|
post_install_message:
|
96
|
-
rdoc_options:
|
97
|
-
|
104
|
+
rdoc_options: []
|
105
|
+
|
98
106
|
require_paths:
|
99
107
|
- lib
|
100
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
101
110
|
requirements:
|
102
111
|
- - ">="
|
103
112
|
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
104
114
|
segments:
|
105
115
|
- 0
|
106
116
|
version: "0"
|
107
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
108
119
|
requirements:
|
109
120
|
- - ">="
|
110
121
|
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
111
123
|
segments:
|
112
124
|
- 0
|
113
125
|
version: "0"
|
114
126
|
requirements: []
|
115
127
|
|
116
128
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
129
|
+
rubygems_version: 1.4.2
|
118
130
|
signing_key:
|
119
131
|
specification_version: 3
|
120
132
|
summary: Automatic Lossless Reduction Of All Your Images
|
data/.gitignore
DELETED