piet 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +48 -8
- data/lib/piet/carrierwave_extension.rb +8 -1
- data/lib/piet/version.rb +1 -1
- data/lib/piet.rb +23 -3
- metadata +18 -7
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/*
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,9 +7,7 @@ Description
|
|
7
7
|
Piet is a gem that optimizes an image stored in a file, and it has
|
8
8
|
integration with CarrierWave uploaders.
|
9
9
|
|
10
|
-
This gem is named after the
|
11
|
-
|
12
|
-
[![Build Status](https://secure.travis-ci.org/albertbellonch/piet.png)](http://travis-ci.org/albertbellonch/piet)
|
10
|
+
This gem is named after the minimalist Dutch painter [Piet Mondrian](http://en.wikipedia.org/wiki/Piet_Mondrian).
|
13
11
|
|
14
12
|
Installation
|
15
13
|
------------
|
@@ -46,24 +44,59 @@ CarrierWave integration
|
|
46
44
|
-----------------------
|
47
45
|
|
48
46
|
As stated before, Piet can be integrated into CarrierWave uploaders.
|
49
|
-
This way, you can optimize the original image or a version
|
47
|
+
This way, you can optimize the original image or a version.
|
48
|
+
|
49
|
+
In order to do that, firstly add **piet** to your Gemfile:
|
50
|
+
|
51
|
+
gem 'piet'
|
52
|
+
|
53
|
+
Then go to your CarrierWave uploader and include Piet's extension:
|
54
|
+
|
55
|
+
class ImageUploader < CarrierWave::Uploader::Base
|
56
|
+
...
|
57
|
+
include Piet::CarrierWaveExtension
|
58
|
+
...
|
59
|
+
end
|
60
|
+
|
61
|
+
And finally use Piet! For all the images:
|
62
|
+
|
63
|
+
class ImageUploader < CarrierWave::Uploader::Base
|
64
|
+
...
|
65
|
+
process :optimize
|
66
|
+
...
|
67
|
+
end
|
68
|
+
|
69
|
+
Or only for a version:
|
70
|
+
|
71
|
+
class ImageUploader < CarrierWave::Uploader::Base
|
72
|
+
...
|
73
|
+
version :normal do
|
74
|
+
...
|
75
|
+
process :optimize
|
76
|
+
end
|
77
|
+
...
|
78
|
+
end
|
50
79
|
|
51
80
|
Examples
|
52
81
|
--------
|
53
82
|
|
54
83
|
* Simply Optimizing
|
55
84
|
|
85
|
+
```
|
56
86
|
Piet.optimize('/my/wonderful/pics/piggy.png')
|
57
87
|
|
58
88
|
Piet.optimize('/my/wonderful/pics/pony.jpg')
|
89
|
+
```
|
59
90
|
|
60
|
-
would optimize those PNG and JPEG files but ouput nothing.
|
91
|
+
would optimize those PNG, GIF and JPEG files but ouput nothing.
|
61
92
|
|
62
|
-
* Optimizing PNG and getting feedback
|
93
|
+
* Optimizing PNG/GIF and getting feedback
|
63
94
|
|
95
|
+
```
|
64
96
|
Piet.optimize('/my/wonderful/pics/piggy.png', :verbose => true)
|
97
|
+
```
|
65
98
|
|
66
|
-
would optimize that PNG file and ouput something similar to this one:
|
99
|
+
would optimize that PNG/GIF file and ouput something similar to this one:
|
67
100
|
|
68
101
|
** Processing: piggy.png
|
69
102
|
340x340 pixels, 4x8 bits/pixel, RGB+alpha
|
@@ -82,7 +115,9 @@ would optimize that PNG file and ouput something similar to this one:
|
|
82
115
|
|
83
116
|
* Optimizing JPEG and getting feedback
|
84
117
|
|
118
|
+
```
|
85
119
|
Piet.optimize('/my/wonderful/pics/pony.jpg', :verbose => true)
|
120
|
+
```
|
86
121
|
|
87
122
|
would optimize that JPEG file and ouput similar to this one:
|
88
123
|
|
@@ -91,6 +126,11 @@ would optimize that JPEG file and ouput similar to this one:
|
|
91
126
|
TODO
|
92
127
|
----
|
93
128
|
|
94
|
-
* Support for GIFs
|
95
129
|
* Binary tool for optimizing a file
|
96
130
|
* Add some testing!
|
131
|
+
|
132
|
+
Changelog
|
133
|
+
---------
|
134
|
+
|
135
|
+
* v.0.1.0 Optimization of PNGs and JPEGs, including an integration with Carrierwave
|
136
|
+
* v.0.1.1 Added support for GIFs. Added an extra option to use pngquant (thanks @rogercampos). Solved problems with Carrierwave >= 0.6 (thanks @mllocs and @huacnlee).
|
data/lib/piet/version.rb
CHANGED
data/lib/piet.rb
CHANGED
@@ -2,19 +2,25 @@ require 'piet/carrierwave_extension'
|
|
2
2
|
|
3
3
|
module Piet
|
4
4
|
class << self
|
5
|
-
VALID_EXTS = %w{ png jpg jpeg }
|
5
|
+
VALID_EXTS = %w{ png gif jpg jpeg }
|
6
6
|
|
7
|
-
def optimize(path, opts={})
|
7
|
+
def optimize(path, opts= {} )
|
8
8
|
output = optimize_for(path, opts)
|
9
9
|
puts output if opts[:verbose]
|
10
10
|
true
|
11
11
|
end
|
12
12
|
|
13
|
+
def pngquant(path, opts = {})
|
14
|
+
output = pngquant_for(path, opts)
|
15
|
+
puts output if opts[:verbose]
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
13
19
|
private
|
14
20
|
|
15
21
|
def optimize_for(path, opts)
|
16
22
|
case extension(path)
|
17
|
-
when "png" then optimize_png(path, opts)
|
23
|
+
when "png", "gif" then optimize_png(path, opts)
|
18
24
|
when "jpg", "jpeg" then optimize_jpg(path, opts)
|
19
25
|
end
|
20
26
|
end
|
@@ -32,5 +38,19 @@ module Piet
|
|
32
38
|
vo = opts[:verbose] ? "-v" : "-q"
|
33
39
|
`jpegoptim -f --strip-all #{vo} #{path}`
|
34
40
|
end
|
41
|
+
|
42
|
+
def pngquant_for(path, opts)
|
43
|
+
opts.merge!({:force => true})
|
44
|
+
vo = if opts.any?
|
45
|
+
opts.keys.map{|x| "-#{x}"}.join(" ")
|
46
|
+
else
|
47
|
+
""
|
48
|
+
end
|
49
|
+
out = `pngquant #{vo} 256 #{path}`
|
50
|
+
blobs = path.split(".")
|
51
|
+
new_path = "#{blobs[0..-2].join(".")}-fs8.#{blobs[-1]}"
|
52
|
+
`mv #{new_path} #{path}`
|
53
|
+
out
|
54
|
+
end
|
35
55
|
end
|
36
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: piet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-10-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: ZenTest
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
description: ! '-'
|
37
47
|
email:
|
38
48
|
- albert@itnig.net
|
@@ -40,6 +50,7 @@ executables: []
|
|
40
50
|
extensions: []
|
41
51
|
extra_rdoc_files: []
|
42
52
|
files:
|
53
|
+
- .gitignore
|
43
54
|
- Gemfile
|
44
55
|
- Gemfile.lock
|
45
56
|
- README.md
|
@@ -70,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
81
|
version: '0'
|
71
82
|
requirements: []
|
72
83
|
rubyforge_project: piet
|
73
|
-
rubygems_version: 1.8.
|
84
|
+
rubygems_version: 1.8.24
|
74
85
|
signing_key:
|
75
86
|
specification_version: 3
|
76
87
|
summary: An image optimizer
|