piet 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -0
- data/.travis.yml +4 -0
- data/Gemfile.lock +42 -11
- data/README.md +14 -6
- data/Rakefile +6 -0
- data/lib/piet.rb +6 -7
- data/lib/piet/carrierwave_extension.rb +3 -9
- data/lib/piet/version.rb +1 -1
- data/piet.gemspec +4 -0
- data/spec/assets/jpg-fake.jpg +0 -0
- data/spec/assets/jpg-real.jpg +0 -0
- data/spec/assets/png-fake.png +0 -0
- data/spec/assets/png-real.png +0 -0
- data/spec/integration/piet_spec.rb +95 -0
- data/spec/spec_helper.rb +1 -0
- metadata +67 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f156bb74824772e7b12d94c41f0a6e16cddc35de
|
4
|
+
data.tar.gz: d621ebeb34ec00912b4691dbc135de77fd5f54bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 434517ed09c979627074dc10dc16d7834ca53eb90f26e9f26971c9688ccfbe83637c2937c8ca638002212e4878c7ebf68d76090dbd916c9d3f940f3697e86ca1
|
7
|
+
data.tar.gz: 36592b89e4613eca1f2a6a79dbb956c40fa97c59e6d8cc78834ffaf657fd31080a618a05ed055d4b2f0829dc645d3ba07e48c4c0b2ca6a62d4564b3a00482f6a
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,28 +1,59 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
piet (0.
|
4
|
+
piet (0.2.0)
|
5
5
|
png_quantizator
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
ZenTest (4.
|
11
|
-
|
10
|
+
ZenTest (4.10.0)
|
11
|
+
activemodel (4.1.1)
|
12
|
+
activesupport (= 4.1.1)
|
13
|
+
builder (~> 3.1)
|
14
|
+
activesupport (4.1.1)
|
15
|
+
i18n (~> 0.6, >= 0.6.9)
|
16
|
+
json (~> 1.7, >= 1.7.7)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
thread_safe (~> 0.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
builder (3.2.2)
|
21
|
+
carrierwave (0.10.0)
|
22
|
+
activemodel (>= 3.2.0)
|
23
|
+
activesupport (>= 3.2.0)
|
24
|
+
json (>= 1.7)
|
25
|
+
mime-types (>= 1.16)
|
26
|
+
diff-lcs (1.2.5)
|
27
|
+
i18n (0.6.9)
|
28
|
+
json (1.8.1)
|
29
|
+
mime-types (2.2)
|
30
|
+
mini_magick (3.7.0)
|
31
|
+
subexec (~> 0.2.1)
|
32
|
+
minitest (5.3.3)
|
12
33
|
png_quantizator (0.1.0)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
rspec-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
rspec-
|
34
|
+
rake (10.3.2)
|
35
|
+
rmagick (2.13.2)
|
36
|
+
rspec (2.14.1)
|
37
|
+
rspec-core (~> 2.14.0)
|
38
|
+
rspec-expectations (~> 2.14.0)
|
39
|
+
rspec-mocks (~> 2.14.0)
|
40
|
+
rspec-core (2.14.8)
|
41
|
+
rspec-expectations (2.14.5)
|
42
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
43
|
+
rspec-mocks (2.14.6)
|
44
|
+
subexec (0.2.3)
|
45
|
+
thread_safe (0.3.3)
|
46
|
+
tzinfo (1.1.0)
|
47
|
+
thread_safe (~> 0.1)
|
21
48
|
|
22
49
|
PLATFORMS
|
23
50
|
ruby
|
24
51
|
|
25
52
|
DEPENDENCIES
|
26
53
|
ZenTest
|
54
|
+
carrierwave
|
55
|
+
mini_magick
|
27
56
|
piet!
|
57
|
+
rake
|
58
|
+
rmagick
|
28
59
|
rspec
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Piet
|
2
2
|
======
|
3
3
|
|
4
|
+
[![Build Status](https://secure.travis-ci.org/albertbellonch/piet.png)](http://travis-ci.org/albertbellonch/piet)
|
5
|
+
|
4
6
|
Description
|
5
7
|
-----------
|
6
8
|
|
@@ -62,12 +64,16 @@ and then call the **optimize** method:
|
|
62
64
|
Piet.optimize(path, opts)
|
63
65
|
```
|
64
66
|
|
67
|
+
Not that this will work not by just using the file extension, but by
|
68
|
+
MIME type detection, which should be more reliable.
|
69
|
+
|
65
70
|
The options are:
|
66
71
|
|
67
72
|
* **verbose**: Whether you want to get the output of the command or not. It is interpreted as a Boolean value. Default: false.
|
68
73
|
|
69
|
-
* **quality**:
|
74
|
+
* **quality**: Adjust the output compression for JPEGs. Valid values are any integer between 0 and 100 (100 means no compression and highest quality). Default: 100
|
70
75
|
|
76
|
+
* **level**: Adjust the optimization level for PNGs. Valid values are any integer between 0 and 7 (7 means highest compression and longest processing time). Default: 7
|
71
77
|
|
72
78
|
CarrierWave integration
|
73
79
|
-----------------------
|
@@ -133,7 +139,7 @@ would optimize those PNG, GIF and JPEG files but ouput nothing.
|
|
133
139
|
Piet.optimize('/my/wonderful/pics/piggy.png', :verbose => true)
|
134
140
|
```
|
135
141
|
|
136
|
-
would optimize that PNG/GIF file and
|
142
|
+
would optimize that PNG/GIF file and output something similar to this one:
|
137
143
|
|
138
144
|
** Processing: piggy.png
|
139
145
|
340x340 pixels, 4x8 bits/pixel, RGB+alpha
|
@@ -182,8 +188,10 @@ TODO
|
|
182
188
|
Changelog
|
183
189
|
---------
|
184
190
|
|
185
|
-
* v.0.1
|
186
|
-
|
187
|
-
* v.0.
|
191
|
+
* v.0.2.1 More reliable file type detection, by not using the extension but the MIME type. Thanks to @jewlofthelotus! Also, the Carrierwave
|
192
|
+
extension is now compatible with RMagick thanks to @YoranBrondsema.
|
193
|
+
* v.0.2.0 Users of the gem can now use piet-binary gem, and bug with filenames containing spaces, parentheses and some other characters is solved too, thanks to @loureirorg. Requiring png_quantizator when it's due, thanks to @jayzes. Finally, specifying the gem version due to @jigfox interest.
|
188
194
|
* v.0.1.3 Use png_quantizator gem instead of the own implementation.
|
189
|
-
* v.0.2
|
195
|
+
* v.0.1.2 Fixed some problems with missing processing, thanks to @lentg.
|
196
|
+
* 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).
|
197
|
+
* v.0.1.0 Optimization of PNGs and JPEGs, including an integration with Carrierwave
|
data/Rakefile
CHANGED
data/lib/piet.rb
CHANGED
@@ -3,8 +3,6 @@ require 'piet/carrierwave_extension'
|
|
3
3
|
|
4
4
|
module Piet
|
5
5
|
class << self
|
6
|
-
VALID_EXTS = %w{ png gif jpg jpeg }
|
7
|
-
|
8
6
|
def optimize(path, opts={})
|
9
7
|
output = optimize_for(path, opts)
|
10
8
|
puts output if opts[:verbose]
|
@@ -18,20 +16,21 @@ module Piet
|
|
18
16
|
private
|
19
17
|
|
20
18
|
def optimize_for(path, opts)
|
21
|
-
case
|
19
|
+
case mimetype(path)
|
22
20
|
when "png", "gif" then optimize_png(path, opts)
|
23
|
-
when "
|
21
|
+
when "jpeg" then optimize_jpg(path, opts)
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
|
-
def
|
28
|
-
|
25
|
+
def mimetype(path)
|
26
|
+
IO.popen(['file', '--brief', '--mime-type', path], in: :close, err: :close).read.chomp.sub(/image\//, '')
|
29
27
|
end
|
30
28
|
|
31
29
|
def optimize_png(path, opts)
|
30
|
+
level = (0..7).include?(opts[:level]) ? opts[:level] : 7
|
32
31
|
vo = opts[:verbose] ? "-v" : "-quiet"
|
33
32
|
path.gsub!(/([\(\)\[\]\{\}\*\?\\])/, '\\\\\1')
|
34
|
-
`#{command_path("optipng")} -
|
33
|
+
`#{command_path("optipng")} -o#{level} #{opts[:command_options]} #{vo} #{path}`
|
35
34
|
end
|
36
35
|
|
37
36
|
def optimize_jpg(path, opts)
|
@@ -1,17 +1,11 @@
|
|
1
1
|
module Piet
|
2
2
|
module CarrierWaveExtension
|
3
|
-
def optimize(opts={})
|
4
|
-
|
5
|
-
Piet.optimize(img.path, opts)
|
6
|
-
img
|
7
|
-
end
|
3
|
+
def optimize(opts = {})
|
4
|
+
::Piet.optimize(current_path, opts)
|
8
5
|
end
|
9
6
|
|
10
7
|
def pngquant
|
11
|
-
|
12
|
-
Piet.pngquant(current_path)
|
13
|
-
img
|
14
|
-
end
|
8
|
+
::Piet.pngquant(current_path)
|
15
9
|
end
|
16
10
|
end
|
17
11
|
end
|
data/lib/piet/version.rb
CHANGED
data/piet.gemspec
CHANGED
@@ -21,4 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency "png_quantizator"
|
22
22
|
s.add_development_dependency "rspec"
|
23
23
|
s.add_development_dependency "ZenTest"
|
24
|
+
s.add_development_dependency "carrierwave"
|
25
|
+
s.add_development_dependency "mini_magick"
|
26
|
+
s.add_development_dependency "rmagick"
|
27
|
+
s.add_development_dependency "rake"
|
24
28
|
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1 +1,96 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
|
3
|
+
class RMagickUploader < CarrierWave::Uploader::Base
|
4
|
+
include CarrierWave::RMagick
|
5
|
+
include Piet::CarrierWaveExtension
|
6
|
+
end
|
7
|
+
|
8
|
+
class MiniMagickUploader < CarrierWave::Uploader::Base
|
9
|
+
include CarrierWave::MiniMagick
|
10
|
+
include Piet::CarrierWaveExtension
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Piet do
|
14
|
+
describe Piet::CarrierWaveExtension do
|
15
|
+
describe ".optimize" do
|
16
|
+
let(:real_jpg_path) { File.join('spec', 'assets', 'jpg-real.jpg') }
|
17
|
+
let(:real_jpg_image) { File.open(real_jpg_path) }
|
18
|
+
|
19
|
+
let(:fake_jpg_path) { File.join('spec', 'assets', 'jpg-fake.jpg') }
|
20
|
+
let(:fake_jpg_image) { File.open(fake_jpg_path) }
|
21
|
+
|
22
|
+
let(:real_png_path) { File.join('spec', 'assets', 'png-real.png') }
|
23
|
+
let(:real_png_image) { File.open(real_png_path) }
|
24
|
+
|
25
|
+
let(:fake_png_path) { File.join('spec', 'assets', 'png-fake.png') }
|
26
|
+
let(:fake_png_image) { File.open(fake_png_path) }
|
27
|
+
|
28
|
+
def upload_file(uploader, image)
|
29
|
+
uploader.store!(image)
|
30
|
+
uploader.manipulate! do |img|
|
31
|
+
img
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "calls the uploader's `current_path` when MiniMagick is used" do
|
36
|
+
uploader = MiniMagickUploader.new
|
37
|
+
|
38
|
+
upload_file(uploader, real_jpg_image)
|
39
|
+
|
40
|
+
expect(Piet).to receive(:optimize).with(uploader.current_path, {})
|
41
|
+
|
42
|
+
uploader.optimize
|
43
|
+
end
|
44
|
+
|
45
|
+
it "calls the uploader's `current_path` when RMagick is used" do
|
46
|
+
uploader = RMagickUploader.new
|
47
|
+
|
48
|
+
upload_file(uploader, real_jpg_image)
|
49
|
+
|
50
|
+
expect(Piet).to receive(:optimize).with(uploader.current_path, {})
|
51
|
+
|
52
|
+
uploader.optimize
|
53
|
+
end
|
54
|
+
|
55
|
+
it "calls `optimize_png` if the .png files MIME type is that of a PNG" do
|
56
|
+
uploader = MiniMagickUploader.new
|
57
|
+
|
58
|
+
upload_file(uploader, real_png_image)
|
59
|
+
|
60
|
+
expect(Piet).to receive(:optimize_png).with(uploader.current_path, {})
|
61
|
+
|
62
|
+
uploader.optimize
|
63
|
+
end
|
64
|
+
|
65
|
+
it "calls `optimize_jpg` if the .png files MIME type is that of a JPEG" do
|
66
|
+
uploader = MiniMagickUploader.new
|
67
|
+
|
68
|
+
upload_file(uploader, fake_png_image)
|
69
|
+
|
70
|
+
expect(Piet).to receive(:optimize_jpg).with(uploader.current_path, {})
|
71
|
+
|
72
|
+
uploader.optimize
|
73
|
+
end
|
74
|
+
|
75
|
+
it "calls `optimize_png` if the .jpg files MIME type is that of a PNG" do
|
76
|
+
uploader = MiniMagickUploader.new
|
77
|
+
|
78
|
+
upload_file(uploader, fake_jpg_image)
|
79
|
+
|
80
|
+
expect(Piet).to receive(:optimize_png).with(uploader.current_path, {})
|
81
|
+
|
82
|
+
uploader.optimize
|
83
|
+
end
|
84
|
+
|
85
|
+
it "calls `optimize_jpg` if the .jpg files MIME type is that of a JPEG" do
|
86
|
+
uploader = MiniMagickUploader.new
|
87
|
+
|
88
|
+
upload_file(uploader, real_jpg_image)
|
89
|
+
|
90
|
+
expect(Piet).to receive(:optimize_jpg).with(uploader.current_path, {})
|
91
|
+
|
92
|
+
uploader.optimize
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: piet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Albert Bellonch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: png_quantizator
|
@@ -52,6 +52,62 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: carrierwave
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mini_magick
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rmagick
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
55
111
|
description: "-"
|
56
112
|
email:
|
57
113
|
- albert@itnig.net
|
@@ -60,6 +116,7 @@ extensions: []
|
|
60
116
|
extra_rdoc_files: []
|
61
117
|
files:
|
62
118
|
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
63
120
|
- Gemfile
|
64
121
|
- Gemfile.lock
|
65
122
|
- README.md
|
@@ -68,6 +125,10 @@ files:
|
|
68
125
|
- lib/piet/carrierwave_extension.rb
|
69
126
|
- lib/piet/version.rb
|
70
127
|
- piet.gemspec
|
128
|
+
- spec/assets/jpg-fake.jpg
|
129
|
+
- spec/assets/jpg-real.jpg
|
130
|
+
- spec/assets/png-fake.png
|
131
|
+
- spec/assets/png-real.png
|
71
132
|
- spec/integration/piet_spec.rb
|
72
133
|
- spec/spec_helper.rb
|
73
134
|
homepage: http://itnig.net
|
@@ -95,5 +156,9 @@ signing_key:
|
|
95
156
|
specification_version: 4
|
96
157
|
summary: An image optimizer
|
97
158
|
test_files:
|
159
|
+
- spec/assets/jpg-fake.jpg
|
160
|
+
- spec/assets/jpg-real.jpg
|
161
|
+
- spec/assets/png-fake.png
|
162
|
+
- spec/assets/png-real.png
|
98
163
|
- spec/integration/piet_spec.rb
|
99
164
|
- spec/spec_helper.rb
|