scale_down 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +6 -1
- data/README.rdoc +4 -4
- data/lib/scale_down/controller.rb +11 -4
- data/lib/scale_down/image.rb +4 -1
- data/lib/scale_down/scaler.rb +10 -0
- data/lib/scale_down/version.rb +1 -1
- data/lib/scale_down.rb +1 -0
- data/scale_down.gemspec +1 -0
- data/test/scale_down/controller_test.rb +26 -2
- data/test/scale_down/scaler_test.rb +15 -0
- metadata +25 -10
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
scale_down (0.0
|
4
|
+
scale_down (0.1.0)
|
5
|
+
mini_magick (>= 2.3)
|
5
6
|
rmagick (>= 2.1)
|
6
7
|
ruby-hmac (>= 0.4.0)
|
7
8
|
sinatra (>= 1.0)
|
@@ -10,6 +11,8 @@ GEM
|
|
10
11
|
remote: http://rubygems.org/
|
11
12
|
specs:
|
12
13
|
contest (0.1.2)
|
14
|
+
mini_magick (2.3)
|
15
|
+
subexec (~> 0.0.4)
|
13
16
|
mocha (0.9.8)
|
14
17
|
rake
|
15
18
|
rack (1.2.1)
|
@@ -20,12 +23,14 @@ GEM
|
|
20
23
|
ruby-hmac (0.4.0)
|
21
24
|
sinatra (1.0)
|
22
25
|
rack (>= 1.0)
|
26
|
+
subexec (0.0.4)
|
23
27
|
|
24
28
|
PLATFORMS
|
25
29
|
ruby
|
26
30
|
|
27
31
|
DEPENDENCIES
|
28
32
|
contest (>= 0.1.2)
|
33
|
+
mini_magick (>= 2.3)
|
29
34
|
mocha (= 0.9.8)
|
30
35
|
rack-test (= 0.5.6)
|
31
36
|
rmagick (>= 2.1)
|
data/README.rdoc
CHANGED
@@ -25,6 +25,10 @@ For example, to ensure an image is 300 pixels wide
|
|
25
25
|
|
26
26
|
http://images.example.com/images/logo.png/300xauto/A3SDACEDF
|
27
27
|
|
28
|
+
There is a very simple `/info` function for getting the image dimesions. It just returns a string with the WIDTHxHEIGHT.
|
29
|
+
|
30
|
+
http://images.exmaple.com/images/logo.png/info
|
31
|
+
|
28
32
|
== Installation and Configuration
|
29
33
|
|
30
34
|
gem install scale_down
|
@@ -78,10 +82,6 @@ Of course this could be done in PHP, Python, or whatever language your applicati
|
|
78
82
|
|
79
83
|
== TODO
|
80
84
|
|
81
|
-
This thing is brand spankin new and is in flux - expect changes.
|
82
|
-
|
83
|
-
Define a max image size (do not scale images over this size).
|
84
|
-
|
85
85
|
Support DELETE requests to remove scaled images.
|
86
86
|
|
87
87
|
Custom Read/Write methods to allow for more than just local storage.
|
@@ -8,9 +8,17 @@ class ScaleDown::Controller < Sinatra::Application
|
|
8
8
|
"<b>ScaleDown version #{ScaleDown::VERSION}<b/>"
|
9
9
|
end
|
10
10
|
|
11
|
+
get '/*/info' do
|
12
|
+
info = ScaleDown::Scaler.info(params[:splat].join("/"))
|
13
|
+
if info
|
14
|
+
[200, info]
|
15
|
+
else
|
16
|
+
[404, "Image not found"]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
# get '/*/:filename/:geometry/:hmac'
|
12
|
-
# is what I want, but
|
13
|
-
# this fails when the URL includes things like %23 (an encoded hash tag)
|
21
|
+
# is what I want, but this fails when the URL includes things like %23 (an encoded hash tag)
|
14
22
|
get '/*' do
|
15
23
|
parts = params[:splat].join("/").split("/")
|
16
24
|
|
@@ -20,7 +28,6 @@ class ScaleDown::Controller < Sinatra::Application
|
|
20
28
|
:filename => parts.pop,
|
21
29
|
:splat => parts
|
22
30
|
}
|
23
|
-
|
24
31
|
path, status = scaler(params)
|
25
32
|
|
26
33
|
# TODO Eh? Shouldn't it be if 301
|
@@ -36,7 +43,7 @@ class ScaleDown::Controller < Sinatra::Application
|
|
36
43
|
def scaler(params)
|
37
44
|
ScaleDown::Scaler.process \
|
38
45
|
:path => params[:splat].join("/"),
|
39
|
-
:filename =>
|
46
|
+
:filename => params[:filename],
|
40
47
|
:geometry => params[:geometry],
|
41
48
|
:hmac => params[:hmac]
|
42
49
|
end
|
data/lib/scale_down/image.rb
CHANGED
data/lib/scale_down/scaler.rb
CHANGED
@@ -14,6 +14,16 @@ class ScaleDown::Scaler
|
|
14
14
|
["Error message", 403]
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
def info(relative_path)
|
19
|
+
path = [ScaleDown.root_path, relative_path].join("/")
|
20
|
+
if File.exists?(path)
|
21
|
+
image = MiniMagick::Image.open(path)
|
22
|
+
[image[:width],image[:height]].join('x')
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
17
27
|
end
|
18
28
|
|
19
29
|
def initialize(params)
|
data/lib/scale_down/version.rb
CHANGED
data/lib/scale_down.rb
CHANGED
data/scale_down.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency "rmagick", ">= 2.1"
|
18
18
|
s.add_dependency "sinatra", ">= 1.0"
|
19
19
|
s.add_dependency "ruby-hmac", ">= 0.4.0"
|
20
|
+
s.add_dependency "mini_magick", ">= 2.3"
|
20
21
|
|
21
22
|
s.add_development_dependency "contest", ">= 0.1.2"
|
22
23
|
s.add_development_dependency "mocha", "0.9.8"
|
@@ -8,7 +8,6 @@ class ScaleDown::Controller::Test < Test::Unit::TestCase
|
|
8
8
|
end
|
9
9
|
|
10
10
|
context "parsing a request" do
|
11
|
-
|
12
11
|
should "have an image path" do
|
13
12
|
ScaleDown::Scaler.expects(:process).with(
|
14
13
|
:path => "user/path",
|
@@ -22,7 +21,6 @@ class ScaleDown::Controller::Test < Test::Unit::TestCase
|
|
22
21
|
end
|
23
22
|
|
24
23
|
context "a valid request" do
|
25
|
-
|
26
24
|
should "redirect to the image path" do
|
27
25
|
ScaleDown::Scaler.expects(:process).returns ["/image-path", 301]
|
28
26
|
get "/path/filename/geo/hmac"
|
@@ -33,6 +31,7 @@ class ScaleDown::Controller::Test < Test::Unit::TestCase
|
|
33
31
|
end
|
34
32
|
|
35
33
|
context "an invalid request" do
|
34
|
+
|
36
35
|
should "respond with a 403 and error message" do
|
37
36
|
ScaleDown::Scaler.expects(:process).returns ["Error description", 403]
|
38
37
|
|
@@ -43,4 +42,29 @@ class ScaleDown::Controller::Test < Test::Unit::TestCase
|
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
45
|
+
context "get dimensions" do
|
46
|
+
context "for image which exists" do
|
47
|
+
setup do
|
48
|
+
ScaleDown::Scaler.expects(:info).with("image/path/image.jpg").returns "400x300"
|
49
|
+
end
|
50
|
+
|
51
|
+
should "return the width and height as json" do
|
52
|
+
get "/image/path/image.jpg/info"
|
53
|
+
|
54
|
+
assert_equal 200, last_response.status
|
55
|
+
assert_equal "400x300", last_response.body
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "for a non-existant image" do
|
60
|
+
setup do
|
61
|
+
ScaleDown::Scaler.expects(:info).with("image/path/image.jpg").returns nil
|
62
|
+
end
|
63
|
+
|
64
|
+
should "respond with a 404" do
|
65
|
+
get "/image/path/image.jpg/info"
|
66
|
+
assert_equal 404, last_response.status
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
46
70
|
end
|
@@ -122,4 +122,19 @@ class ScaleDown::Scaler::Test < Test::Unit::TestCase
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
125
|
+
|
126
|
+
context "#info" do
|
127
|
+
setup do
|
128
|
+
ScaleDown.root_path = File.join(File.expand_path(File.dirname(__FILE__)), "..")
|
129
|
+
end
|
130
|
+
|
131
|
+
should "return the width x height for an image" do
|
132
|
+
assert_equal "200x400", ScaleDown::Scaler.info("files/graphic.png")
|
133
|
+
end
|
134
|
+
|
135
|
+
should "return nil for a non-existant image" do
|
136
|
+
assert_equal nil, ScaleDown::Scaler.info("files/notthere.jpg")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
125
140
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scale_down
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.5
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Weir
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-01 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -65,9 +65,24 @@ dependencies:
|
|
65
65
|
type: :runtime
|
66
66
|
version_requirements: *id003
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
68
|
+
name: mini_magick
|
69
69
|
prerelease: false
|
70
70
|
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 5
|
76
|
+
segments:
|
77
|
+
- 2
|
78
|
+
- 3
|
79
|
+
version: "2.3"
|
80
|
+
type: :runtime
|
81
|
+
version_requirements: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: contest
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
71
86
|
none: false
|
72
87
|
requirements:
|
73
88
|
- - ">="
|
@@ -79,11 +94,11 @@ dependencies:
|
|
79
94
|
- 2
|
80
95
|
version: 0.1.2
|
81
96
|
type: :development
|
82
|
-
version_requirements: *
|
97
|
+
version_requirements: *id005
|
83
98
|
- !ruby/object:Gem::Dependency
|
84
99
|
name: mocha
|
85
100
|
prerelease: false
|
86
|
-
requirement: &
|
101
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
87
102
|
none: false
|
88
103
|
requirements:
|
89
104
|
- - "="
|
@@ -95,11 +110,11 @@ dependencies:
|
|
95
110
|
- 8
|
96
111
|
version: 0.9.8
|
97
112
|
type: :development
|
98
|
-
version_requirements: *
|
113
|
+
version_requirements: *id006
|
99
114
|
- !ruby/object:Gem::Dependency
|
100
115
|
name: rack-test
|
101
116
|
prerelease: false
|
102
|
-
requirement: &
|
117
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
103
118
|
none: false
|
104
119
|
requirements:
|
105
120
|
- - "="
|
@@ -111,7 +126,7 @@ dependencies:
|
|
111
126
|
- 6
|
112
127
|
version: 0.5.6
|
113
128
|
type: :development
|
114
|
-
version_requirements: *
|
129
|
+
version_requirements: *id007
|
115
130
|
description: ""
|
116
131
|
email:
|
117
132
|
- john@famedriver.com
|