asset-image-opt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/asset-image-opt.gemspec +21 -0
- data/bin/optimize_images +9 -0
- data/lib/asset-image-opt.rb +52 -0
- data/lib/asset-image-opt/version.rb +7 -0
- data/spec/image_optimizer_spec.rb +32 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/test_files/app/assets/images/1.jpeg +0 -0
- data/spec/test_files/app/assets/images/1.jpg +0 -0
- data/spec/test_files/app/assets/images/1.png +0 -0
- data/spec/test_files/app/assets/images/2.jpeg +0 -0
- data/spec/test_files/app/assets/images/2.jpg +0 -0
- data/spec/test_files/app/assets/images/2.png +0 -0
- data/spec/test_files/app/assets/images/3.jpg +0 -0
- data/spec/test_files/app/assets/images/3.png +0 -0
- data/spec/test_files/app/assets/images/4.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_1/1.jpeg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_1/1.jpg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_1/1.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_1/2.jpeg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_1/2.jpg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_1/2.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_1/3.jpg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_1/3.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_1/4.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_2/1.jpeg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_2/1.jpg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_2/1.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_2/2.jpeg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_2/2.jpg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_2/2.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_2/3.jpg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_2/3.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_2/4.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_3/1.jpeg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_3/1.jpg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_3/1.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_3/2.jpeg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_3/2.jpg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_3/2.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_3/3.jpeg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_3/3.jpg +0 -0
- data/spec/test_files/app/assets/images/sub_dir_3/3.png +0 -0
- data/spec/test_files/app/assets/images/sub_dir_3/4.png +0 -0
- metadata +166 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Oleg Bovykin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Asset-Image-Opt
|
2
|
+
|
3
|
+
Local assets optimizer for Rails apps
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
This gem requires two image optimization utilities: **optipng** and
|
8
|
+
**jpegoptim**.
|
9
|
+
You can install them by following the instructions on each authors'
|
10
|
+
page:
|
11
|
+
|
12
|
+
* Installation for [optipng](http://optipng.sourceforge.net/)
|
13
|
+
* Installation for [jpegoptim](http://freecode.com/projects/jpegoptim)
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'asset-image-opt'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
Execute:
|
25
|
+
|
26
|
+
bundle exec optimize_images
|
27
|
+
|
28
|
+
It will optimize all images in app/assets/images
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'asset-image-opt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "asset-image-opt"
|
8
|
+
gem.version = Asset::Image::Opt::VERSION
|
9
|
+
gem.authors = ["Oleg Bovykin"]
|
10
|
+
gem.email = ["oleg.bovykin@gmail.com"]
|
11
|
+
gem.description = %q{Lossless optimization for rails assets images}
|
12
|
+
gem.summary = %q{Gem is a command line tool for optimization of rails assets images in app/assets.images}
|
13
|
+
gem.homepage = "https://github.com/arrowcircle/asset-image-opt"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency 'piet'
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
end
|
data/bin/optimize_images
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'asset-image-opt'
|
4
|
+
opt = AssetImageOpt.new
|
5
|
+
puts "Total files: #{opt.files.count}"
|
6
|
+
puts "Total size: #{opt.initial_size}"
|
7
|
+
opt.optimize
|
8
|
+
puts "Total optimized size: #{opt.optimized_size}" if opt.optimized_size
|
9
|
+
puts "Win: #{(opt.initial_size.to_f/opt.optimized_size.to_f - 1.0)*10000.0/100} %" if opt.optimized_size
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "asset-image-opt/version"
|
2
|
+
require 'piet'
|
3
|
+
|
4
|
+
class AssetImageOpt
|
5
|
+
EXTENSIONS = %w{png jpeg jpg}
|
6
|
+
WORKING_DIR = "app/assets/images"
|
7
|
+
|
8
|
+
attr_accessor :files, :initial_size, :optimized_size
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@files = AssetImageOpt.get_files
|
12
|
+
@initial_size = get_files_size
|
13
|
+
end
|
14
|
+
|
15
|
+
def optimize
|
16
|
+
if @files.empty?
|
17
|
+
puts "No files to optimize"
|
18
|
+
else
|
19
|
+
puts "Optimizing images"
|
20
|
+
@files.each do |file|
|
21
|
+
optimize_file(file)
|
22
|
+
print '.'
|
23
|
+
end
|
24
|
+
@optimized_size = get_files_size
|
25
|
+
puts ""
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get_files_for_ext(ext)
|
30
|
+
Dir.glob("#{Dir.pwd}/#{WORKING_DIR}/**/*.#{ext}")
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.get_files
|
34
|
+
res = []
|
35
|
+
EXTENSIONS.each do |ext|
|
36
|
+
res += AssetImageOpt.get_files_for_ext(ext)
|
37
|
+
end
|
38
|
+
res
|
39
|
+
end
|
40
|
+
|
41
|
+
def optimize_file(file)
|
42
|
+
Piet.optimize(file)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_files_size
|
46
|
+
size = 0
|
47
|
+
@files.each do |file|
|
48
|
+
size += File.size(file)
|
49
|
+
end
|
50
|
+
size
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AssetImageOpt do
|
4
|
+
before :each do
|
5
|
+
`cp -R spec/test_files/app .`
|
6
|
+
@opt = AssetImageOpt.new
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
`rm -Rf app`
|
11
|
+
end
|
12
|
+
it "should get list of all images in assets folder" do
|
13
|
+
AssetImageOpt.get_files_for_ext("png").count.should == 16
|
14
|
+
AssetImageOpt.get_files_for_ext("jpg").count.should == 12
|
15
|
+
AssetImageOpt.get_files_for_ext("jpeg").count.should == 9
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should get all images" do
|
19
|
+
AssetImageOpt.get_files.count.should == 37
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set size of all files" do
|
23
|
+
opt = AssetImageOpt.new
|
24
|
+
opt.initial_size.should == 1544307
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should compress images" do
|
28
|
+
opt = AssetImageOpt.new
|
29
|
+
opt.optimize
|
30
|
+
opt.optimized_size.should < opt.initial_size
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asset-image-opt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Oleg Bovykin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: piet
|
16
|
+
prerelease: false
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
none: false
|
23
|
+
type: :runtime
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ! '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
none: false
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
prerelease: false
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
none: false
|
39
|
+
type: :development
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
none: false
|
46
|
+
description: Lossless optimization for rails assets images
|
47
|
+
email:
|
48
|
+
- oleg.bovykin@gmail.com
|
49
|
+
executables:
|
50
|
+
- optimize_images
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .rspec
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- asset-image-opt.gemspec
|
61
|
+
- bin/optimize_images
|
62
|
+
- lib/asset-image-opt.rb
|
63
|
+
- lib/asset-image-opt/version.rb
|
64
|
+
- spec/image_optimizer_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
- spec/test_files/app/assets/images/1.jpeg
|
67
|
+
- spec/test_files/app/assets/images/1.jpg
|
68
|
+
- spec/test_files/app/assets/images/1.png
|
69
|
+
- spec/test_files/app/assets/images/2.jpeg
|
70
|
+
- spec/test_files/app/assets/images/2.jpg
|
71
|
+
- spec/test_files/app/assets/images/2.png
|
72
|
+
- spec/test_files/app/assets/images/3.jpg
|
73
|
+
- spec/test_files/app/assets/images/3.png
|
74
|
+
- spec/test_files/app/assets/images/4.png
|
75
|
+
- spec/test_files/app/assets/images/sub_dir_1/1.jpeg
|
76
|
+
- spec/test_files/app/assets/images/sub_dir_1/1.jpg
|
77
|
+
- spec/test_files/app/assets/images/sub_dir_1/1.png
|
78
|
+
- spec/test_files/app/assets/images/sub_dir_1/2.jpeg
|
79
|
+
- spec/test_files/app/assets/images/sub_dir_1/2.jpg
|
80
|
+
- spec/test_files/app/assets/images/sub_dir_1/2.png
|
81
|
+
- spec/test_files/app/assets/images/sub_dir_1/3.jpg
|
82
|
+
- spec/test_files/app/assets/images/sub_dir_1/3.png
|
83
|
+
- spec/test_files/app/assets/images/sub_dir_1/4.png
|
84
|
+
- spec/test_files/app/assets/images/sub_dir_2/1.jpeg
|
85
|
+
- spec/test_files/app/assets/images/sub_dir_2/1.jpg
|
86
|
+
- spec/test_files/app/assets/images/sub_dir_2/1.png
|
87
|
+
- spec/test_files/app/assets/images/sub_dir_2/2.jpeg
|
88
|
+
- spec/test_files/app/assets/images/sub_dir_2/2.jpg
|
89
|
+
- spec/test_files/app/assets/images/sub_dir_2/2.png
|
90
|
+
- spec/test_files/app/assets/images/sub_dir_2/3.jpg
|
91
|
+
- spec/test_files/app/assets/images/sub_dir_2/3.png
|
92
|
+
- spec/test_files/app/assets/images/sub_dir_2/4.png
|
93
|
+
- spec/test_files/app/assets/images/sub_dir_3/1.jpeg
|
94
|
+
- spec/test_files/app/assets/images/sub_dir_3/1.jpg
|
95
|
+
- spec/test_files/app/assets/images/sub_dir_3/1.png
|
96
|
+
- spec/test_files/app/assets/images/sub_dir_3/2.jpeg
|
97
|
+
- spec/test_files/app/assets/images/sub_dir_3/2.jpg
|
98
|
+
- spec/test_files/app/assets/images/sub_dir_3/2.png
|
99
|
+
- spec/test_files/app/assets/images/sub_dir_3/3.jpeg
|
100
|
+
- spec/test_files/app/assets/images/sub_dir_3/3.jpg
|
101
|
+
- spec/test_files/app/assets/images/sub_dir_3/3.png
|
102
|
+
- spec/test_files/app/assets/images/sub_dir_3/4.png
|
103
|
+
homepage: https://github.com/arrowcircle/asset-image-opt
|
104
|
+
licenses: []
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
none: false
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
none: false
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.8.24
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: Gem is a command line tool for optimization of rails assets images in app/assets.images
|
127
|
+
test_files:
|
128
|
+
- spec/image_optimizer_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/test_files/app/assets/images/1.jpeg
|
131
|
+
- spec/test_files/app/assets/images/1.jpg
|
132
|
+
- spec/test_files/app/assets/images/1.png
|
133
|
+
- spec/test_files/app/assets/images/2.jpeg
|
134
|
+
- spec/test_files/app/assets/images/2.jpg
|
135
|
+
- spec/test_files/app/assets/images/2.png
|
136
|
+
- spec/test_files/app/assets/images/3.jpg
|
137
|
+
- spec/test_files/app/assets/images/3.png
|
138
|
+
- spec/test_files/app/assets/images/4.png
|
139
|
+
- spec/test_files/app/assets/images/sub_dir_1/1.jpeg
|
140
|
+
- spec/test_files/app/assets/images/sub_dir_1/1.jpg
|
141
|
+
- spec/test_files/app/assets/images/sub_dir_1/1.png
|
142
|
+
- spec/test_files/app/assets/images/sub_dir_1/2.jpeg
|
143
|
+
- spec/test_files/app/assets/images/sub_dir_1/2.jpg
|
144
|
+
- spec/test_files/app/assets/images/sub_dir_1/2.png
|
145
|
+
- spec/test_files/app/assets/images/sub_dir_1/3.jpg
|
146
|
+
- spec/test_files/app/assets/images/sub_dir_1/3.png
|
147
|
+
- spec/test_files/app/assets/images/sub_dir_1/4.png
|
148
|
+
- spec/test_files/app/assets/images/sub_dir_2/1.jpeg
|
149
|
+
- spec/test_files/app/assets/images/sub_dir_2/1.jpg
|
150
|
+
- spec/test_files/app/assets/images/sub_dir_2/1.png
|
151
|
+
- spec/test_files/app/assets/images/sub_dir_2/2.jpeg
|
152
|
+
- spec/test_files/app/assets/images/sub_dir_2/2.jpg
|
153
|
+
- spec/test_files/app/assets/images/sub_dir_2/2.png
|
154
|
+
- spec/test_files/app/assets/images/sub_dir_2/3.jpg
|
155
|
+
- spec/test_files/app/assets/images/sub_dir_2/3.png
|
156
|
+
- spec/test_files/app/assets/images/sub_dir_2/4.png
|
157
|
+
- spec/test_files/app/assets/images/sub_dir_3/1.jpeg
|
158
|
+
- spec/test_files/app/assets/images/sub_dir_3/1.jpg
|
159
|
+
- spec/test_files/app/assets/images/sub_dir_3/1.png
|
160
|
+
- spec/test_files/app/assets/images/sub_dir_3/2.jpeg
|
161
|
+
- spec/test_files/app/assets/images/sub_dir_3/2.jpg
|
162
|
+
- spec/test_files/app/assets/images/sub_dir_3/2.png
|
163
|
+
- spec/test_files/app/assets/images/sub_dir_3/3.jpeg
|
164
|
+
- spec/test_files/app/assets/images/sub_dir_3/3.jpg
|
165
|
+
- spec/test_files/app/assets/images/sub_dir_3/3.png
|
166
|
+
- spec/test_files/app/assets/images/sub_dir_3/4.png
|