image8 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/image8.gemspec +2 -2
- data/lib/image8.rb +7 -9
- metadata +3 -3
data/image8.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "image8"
|
3
|
-
s.version = "0.
|
4
|
-
s.date = "2010-06-
|
3
|
+
s.version = "0.3"
|
4
|
+
s.date = "2010-06-18"
|
5
5
|
s.summary = "dynamic image resizing."
|
6
6
|
s.email = "harry@vangberg.name"
|
7
7
|
s.homepage = "http://github.com/ichverstehe/image8"
|
data/lib/image8.rb
CHANGED
@@ -14,8 +14,9 @@ class Image8 < Sinatra::Base
|
|
14
14
|
if !request.query_string.empty?
|
15
15
|
uri += "?#{request.query_string}"
|
16
16
|
end
|
17
|
+
uri = URI.encode(uri)
|
17
18
|
|
18
|
-
doc_id =
|
19
|
+
doc_id = encode_uri_for_couchdb(uri)
|
19
20
|
doc_uri = settings.couchdb + "/#{doc_id}"
|
20
21
|
doc_http = EventMachine::HttpRequest.new(doc_uri + "/" + format)
|
21
22
|
|
@@ -23,7 +24,7 @@ class Image8 < Sinatra::Base
|
|
23
24
|
request.callback {
|
24
25
|
expires 31_536_000 # 1 year
|
25
26
|
if request.response_header.status == 200
|
26
|
-
|
27
|
+
puts "Serving straight from cache.."
|
27
28
|
content_type request.response_header["CONTENT_TYPE"]
|
28
29
|
body request.response
|
29
30
|
else
|
@@ -41,7 +42,7 @@ class Image8 < Sinatra::Base
|
|
41
42
|
}
|
42
43
|
end
|
43
44
|
|
44
|
-
def
|
45
|
+
def encode_uri_for_couchdb uri
|
45
46
|
uri = URI.encode(uri)
|
46
47
|
uri.gsub! "/", "%2F"
|
47
48
|
uri
|
@@ -52,10 +53,10 @@ class Image8 < Sinatra::Base
|
|
52
53
|
request = cache.get
|
53
54
|
request.callback {
|
54
55
|
if request.response_header.status == 200
|
55
|
-
|
56
|
+
puts "Serving original from cache.."
|
56
57
|
yield request.response if block_given?
|
57
58
|
else
|
58
|
-
|
59
|
+
puts "Downloading original.."
|
59
60
|
original = EventMachine::HttpRequest.new(uri).get
|
60
61
|
original.callback {
|
61
62
|
req = cache.put(
|
@@ -69,14 +70,11 @@ class Image8 < Sinatra::Base
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def resize_image blob, format, &block
|
72
|
-
|
73
|
-
t1 = Time.now
|
73
|
+
puts "Resizing image.."
|
74
74
|
img = Magick::Image.from_blob(blob).first
|
75
75
|
img.change_geometry!(format) {|width, height|
|
76
76
|
img.resize! width, height
|
77
77
|
}
|
78
|
-
t2 = Time.now
|
79
|
-
p t2 - t1
|
80
78
|
block.call(img) if block
|
81
79
|
end
|
82
80
|
end
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
version: "0.
|
7
|
+
- 3
|
8
|
+
version: "0.3"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Harry Vangberg
|
@@ -13,7 +13,7 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2010-06-
|
16
|
+
date: 2010-06-18 00:00:00 +02:00
|
17
17
|
default_executable:
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|