sprockets-image_compressor 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -9
- data/lib/sprockets/image_compressor.rb +1 -0
- data/lib/sprockets/image_compressor/jpg_compressor.rb +18 -0
- data/lib/sprockets/image_compressor/png_compressor.rb +1 -1
- data/lib/sprockets/image_compressor/railtie.rb +6 -1
- data/lib/sprockets/image_compressor/version.rb +1 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Image compressor processor for Sprockets
|
2
2
|
|
3
|
-
Sprockets preprocessor to losslessly compress images. Requires [pngcrush](http://pmt.sourceforge.net/pngcrush/) to be installed and in your PATH.
|
3
|
+
Sprockets preprocessor to losslessly compress .png and .jpg images. Requires [pngcrush](http://pmt.sourceforge.net/pngcrush/) and [jpegoptim](http://www.kokkonen.net/tjko/projects.html) to be installed and in your PATH.
|
4
4
|
|
5
5
|
## Integration with Rails 3.1+
|
6
6
|
|
@@ -10,16 +10,14 @@ Just add this gem to your Gemfile:
|
|
10
10
|
gem 'sprockets-image_compressor'
|
11
11
|
````
|
12
12
|
|
13
|
-
The gem ships with a Railtie which will automatically register the compressor
|
13
|
+
The gem ships with a Railtie which will automatically register the compressor preprocessors.
|
14
14
|
|
15
|
-
##
|
15
|
+
## TODO
|
16
16
|
|
17
|
-
|
17
|
+
* Detect missing pngcrush or jpegoptim installations
|
18
|
+
* Provide configuration hooks
|
19
|
+
* Tests
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
Also, no tests.
|
22
|
-
|
23
|
-
### License
|
21
|
+
## License
|
24
22
|
|
25
23
|
(MIT License) - Copyright (c) 2011 Micah Geisel
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module ImageCompressor
|
3
|
+
class JpgCompressor
|
4
|
+
def compress(content)
|
5
|
+
compressed_jpg_data = ""
|
6
|
+
Tempfile.open ["file", ".jpg"] do |file|
|
7
|
+
file.write content
|
8
|
+
file.close
|
9
|
+
|
10
|
+
out = `jpegoptim --strip-all #{file.path} 2>&1`
|
11
|
+
file.open
|
12
|
+
compressed_jpg_data = file.read
|
13
|
+
end
|
14
|
+
compressed_jpg_data
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -7,7 +7,7 @@ module Sprockets
|
|
7
7
|
out_file_path = in_file.path + ".optimized.png"
|
8
8
|
in_file.write content
|
9
9
|
in_file.close
|
10
|
-
out = `pngcrush #{in_file.path} #{out_file_path}`
|
10
|
+
out = `pngcrush #{in_file.path} #{out_file_path} 2>&1`
|
11
11
|
in_file.delete
|
12
12
|
|
13
13
|
compressed_png_data = File.read out_file_path
|
@@ -1,12 +1,17 @@
|
|
1
1
|
module Sprockets
|
2
2
|
module ImageCompressor
|
3
3
|
class Railtie < Rails::Engine
|
4
|
-
initializer :
|
4
|
+
initializer :setup_image_compressors do |app|
|
5
5
|
if app.config.assets.compress
|
6
6
|
app.assets.register_mime_type 'image/png', '.png'
|
7
7
|
app.assets.register_postprocessor 'image/png', :png_compressor do |context, data|
|
8
8
|
PngCompressor.new.compress data
|
9
9
|
end
|
10
|
+
|
11
|
+
app.assets.register_mime_type 'image/jpeg', '.jpg'
|
12
|
+
app.assets.register_postprocessor 'image/jpeg', :jpg_compressor do |context, data|
|
13
|
+
JpgCompressor.new.compress data
|
14
|
+
end
|
10
15
|
end
|
11
16
|
end
|
12
17
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-image_compressor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Micah Geisel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-21 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: Losslessly compress images in the Rails asset pipeline
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- Rakefile
|
35
35
|
- lib/sprockets-image_compressor.rb
|
36
36
|
- lib/sprockets/image_compressor.rb
|
37
|
+
- lib/sprockets/image_compressor/jpg_compressor.rb
|
37
38
|
- lib/sprockets/image_compressor/png_compressor.rb
|
38
39
|
- lib/sprockets/image_compressor/railtie.rb
|
39
40
|
- lib/sprockets/image_compressor/version.rb
|