ruby-thumbor 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +43 -4
- data/lib/ruby-thumbor.rb +4 -4
- data/spec/ruby-thumbor_spec.rb +10 -10
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -6,20 +6,59 @@
|
|
6
6
|
|
7
7
|
ruby-thumbor is the client to the thumbor imaging service (http://github.com/globocom/thumbor).
|
8
8
|
|
9
|
-
== FEATURES
|
9
|
+
== FEATURES:
|
10
10
|
|
11
11
|
* Generate thumbor encrypted URLs
|
12
12
|
* Obtain metadata from image operations in thumbor
|
13
13
|
|
14
|
-
==
|
14
|
+
== DEPENDENCIES
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
No dependencies required for regular usage.
|
17
|
+
|
18
|
+
* thumbor (http://github.com/globocom/thumbor) for running ruby-thumbor tests.
|
19
|
+
|
20
|
+
== USAGE:
|
21
|
+
|
22
|
+
crypto = CryptoURL.new :key => 'my-security-key'
|
23
|
+
|
24
|
+
url = crypto.generate :width => 200, :height => 300, :image => 'my.server.com/path/to/image.jpg'
|
25
|
+
|
26
|
+
# url will contain something like:
|
27
|
+
# /2913921in321n3k2nj32hjhj3h22/my.server.com/path/to/image.jpg
|
28
|
+
|
29
|
+
Available arguments to the generate method:
|
30
|
+
|
31
|
+
:meta => bool - flag that indicates that thumbor should return only meta-data on the operations it would
|
32
|
+
otherwise perform;
|
33
|
+
|
34
|
+
:crop => [<int>, <int>, <int>, <int>] - Coordinates for manual cropping. The first item is the two arguments are
|
35
|
+
the coordinates for the left, top point and the last two are the coordinates
|
36
|
+
for the right, bottom point (thus forming the square to crop);
|
37
|
+
|
38
|
+
:width => <int> - the width for the thumbnail;
|
39
|
+
|
40
|
+
:height => <int> - the height for the thumbnail;
|
41
|
+
|
42
|
+
:flip => <bool> - flag that indicates that thumbor should flip horizontally (on the vertical axis) the image;
|
43
|
+
|
44
|
+
:flop => <bool> - flag that indicates that thumbor should flip vertically (on the horizontal axis) the image;
|
45
|
+
|
46
|
+
:halign => :left, :center or :right - horizontal alignment that thumbor should use for cropping;
|
47
|
+
|
48
|
+
:valign => :top, :middle or :bottom - horizontal alignment that thumbor should use for cropping;
|
49
|
+
|
50
|
+
:smart => <bool> - flag that indicates that thumbor should use smart cropping;
|
51
|
+
|
52
|
+
If you need more info on what each option does, check thumbor's documentation at https://github.com/globocom/thumbor/wiki.
|
18
53
|
|
19
54
|
== INSTALL:
|
20
55
|
|
21
56
|
* sudo gem install ruby-thumbor
|
22
57
|
|
58
|
+
== CONTRIBUTIONS:
|
59
|
+
|
60
|
+
* Hugo Lopes (hugobr) - Fixes in the usage readme part of the docs.
|
61
|
+
|
23
62
|
== LICENSE:
|
24
63
|
|
25
64
|
(The MIT License)
|
data/lib/ruby-thumbor.rb
CHANGED
@@ -6,13 +6,13 @@ require 'base64'
|
|
6
6
|
require 'digest/md5'
|
7
7
|
|
8
8
|
module Thumbor
|
9
|
-
VERSION = '0.
|
9
|
+
VERSION = '0.4.0'
|
10
10
|
|
11
11
|
class CryptoURL
|
12
12
|
attr_accessor :key
|
13
13
|
|
14
14
|
def initialize(key)
|
15
|
-
@key = (key * 16)[0..
|
15
|
+
@key = (key * 16)[0..15]
|
16
16
|
end
|
17
17
|
|
18
18
|
def pad(s)
|
@@ -78,11 +78,11 @@ module Thumbor
|
|
78
78
|
|
79
79
|
calculate_width_and_height(url_parts, options)
|
80
80
|
|
81
|
-
if options[:halign] and options[:halign] !=
|
81
|
+
if options[:halign] and options[:halign] != :center
|
82
82
|
url_parts.push(options[:halign])
|
83
83
|
end
|
84
84
|
|
85
|
-
if options[:valign] and options[:valign] !=
|
85
|
+
if options[:valign] and options[:valign] != :middle
|
86
86
|
url_parts.push(options[:valign])
|
87
87
|
end
|
88
88
|
|
data/spec/ruby-thumbor_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe Thumbor::CryptoURL, "#new" do
|
|
17
17
|
|
18
18
|
it "should create a new instance passing key and keep it" do
|
19
19
|
crypto = Thumbor::CryptoURL.new key
|
20
|
-
crypto.key.should == 'my-security-
|
20
|
+
crypto.key.should == 'my-security-keym'
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
@@ -101,7 +101,7 @@ describe Thumbor::CryptoURL, "#url_for" do
|
|
101
101
|
url.should == '-300x0/' << image_md5
|
102
102
|
end
|
103
103
|
|
104
|
-
it "should return proper
|
104
|
+
it "should return proper flop url if height" do
|
105
105
|
crypto = Thumbor::CryptoURL.new key
|
106
106
|
|
107
107
|
url = crypto.url_for :image => image_url, :height => 300, :flop => true
|
@@ -112,7 +112,7 @@ describe Thumbor::CryptoURL, "#url_for" do
|
|
112
112
|
it "should return horizontal align" do
|
113
113
|
crypto = Thumbor::CryptoURL.new key
|
114
114
|
|
115
|
-
url = crypto.url_for :image => image_url, :halign =>
|
115
|
+
url = crypto.url_for :image => image_url, :halign => :left
|
116
116
|
|
117
117
|
url.should == 'left/' << image_md5
|
118
118
|
end
|
@@ -120,7 +120,7 @@ describe Thumbor::CryptoURL, "#url_for" do
|
|
120
120
|
it "should not return horizontal align if it is center" do
|
121
121
|
crypto = Thumbor::CryptoURL.new key
|
122
122
|
|
123
|
-
url = crypto.url_for :image => image_url, :halign =>
|
123
|
+
url = crypto.url_for :image => image_url, :halign => :center
|
124
124
|
|
125
125
|
url.should == image_md5
|
126
126
|
end
|
@@ -128,7 +128,7 @@ describe Thumbor::CryptoURL, "#url_for" do
|
|
128
128
|
it "should return vertical align" do
|
129
129
|
crypto = Thumbor::CryptoURL.new key
|
130
130
|
|
131
|
-
url = crypto.url_for :image => image_url, :valign =>
|
131
|
+
url = crypto.url_for :image => image_url, :valign => :top
|
132
132
|
|
133
133
|
url.should == 'top/' << image_md5
|
134
134
|
end
|
@@ -136,7 +136,7 @@ describe Thumbor::CryptoURL, "#url_for" do
|
|
136
136
|
it "should not return vertical align if it is middle" do
|
137
137
|
crypto = Thumbor::CryptoURL.new key
|
138
138
|
|
139
|
-
url = crypto.url_for :image => image_url, :valign =>
|
139
|
+
url = crypto.url_for :image => image_url, :valign => :middle
|
140
140
|
|
141
141
|
url.should == image_md5
|
142
142
|
end
|
@@ -144,7 +144,7 @@ describe Thumbor::CryptoURL, "#url_for" do
|
|
144
144
|
it "should return halign and valign properly" do
|
145
145
|
crypto = Thumbor::CryptoURL.new key
|
146
146
|
|
147
|
-
url = crypto.url_for :image => image_url, :halign =>
|
147
|
+
url = crypto.url_for :image => image_url, :halign => :left, :valign => :top
|
148
148
|
|
149
149
|
url.should == 'left/top/' << image_md5
|
150
150
|
end
|
@@ -176,7 +176,7 @@ describe Thumbor::CryptoURL, "#url_for" do
|
|
176
176
|
it "should have smart after halign and valign" do
|
177
177
|
crypto = Thumbor::CryptoURL.new key
|
178
178
|
|
179
|
-
url = crypto.url_for :image => image_url, :halign =>
|
179
|
+
url = crypto.url_for :image => image_url, :halign => :left, :valign => :top, :smart => true
|
180
180
|
|
181
181
|
url.should == 'left/top/smart/' << image_md5
|
182
182
|
end
|
@@ -292,7 +292,7 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
292
292
|
crypto = Thumbor::CryptoURL.new key
|
293
293
|
|
294
294
|
url = crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true,
|
295
|
-
:halign =>
|
295
|
+
:halign => :left
|
296
296
|
|
297
297
|
encrypted = url.split('/')[1]
|
298
298
|
|
@@ -313,7 +313,7 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
313
313
|
crypto = Thumbor::CryptoURL.new key
|
314
314
|
|
315
315
|
url = crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true,
|
316
|
-
:halign =>
|
316
|
+
:halign => :left, :valign => :top
|
317
317
|
|
318
318
|
encrypted = url.split('/')[1]
|
319
319
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-thumbor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bernardo Heynemann
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-04 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|