rack_image_resizer 1.2.7 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rack_image_resizer.rb +15 -23
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 317f602a60fc3a621da4897c29786fb636f8155660980b92a1134b74900ad3aa
|
4
|
+
data.tar.gz: 530c8fff285afe3f52e66aec8a2897378d4f97fbcb24aefddfb6099162a9b4d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8820004e65a2dc8c6cf6bb60caeb59cc0ddcbb04539912d59c936c7e0850c8204e61267cab05712e989d411da21074845abbf94a1e3c0a05aa02ab440483aa19
|
7
|
+
data.tar.gz: f5aa083ad8276879d9ce911a4812a1bc0d3b82a1ece44d6b711f762e9b6255e57441b853b7cea62bcbbcac8d28ed61a83a22f9f495c6bf9278f9b48f92b4b7cc
|
data/lib/rack_image_resizer.rb
CHANGED
@@ -6,11 +6,16 @@ module ::RackImageResizer
|
|
6
6
|
extend self
|
7
7
|
|
8
8
|
def resizer_secret
|
9
|
-
ENV.fetch('RESIZER_SECRET')
|
9
|
+
@secret || ENV.fetch('RESIZER_SECRET')
|
10
10
|
end
|
11
11
|
|
12
12
|
def resizer_url
|
13
|
-
ENV.fetch('RESIZER_URL')
|
13
|
+
@url || ENV.fetch('RESIZER_URL')
|
14
|
+
end
|
15
|
+
|
16
|
+
def set name, value
|
17
|
+
raise 'not allowed' unless [:secret, :url].include?(name)
|
18
|
+
instance_variable_set '@%s' % name, value
|
14
19
|
end
|
15
20
|
|
16
21
|
###
|
@@ -18,40 +23,27 @@ module ::RackImageResizer
|
|
18
23
|
# "http://foo.jpg".resize_image({ s: "222x222", q: 80 }
|
19
24
|
# "http://foo.jpg".resize_image("^200x200")
|
20
25
|
# "http://foo.jpg".resize_image - expcts size as param
|
21
|
-
def get opts
|
22
|
-
|
26
|
+
def get opts
|
27
|
+
opts[:i] ||= opts.delete(:image)
|
28
|
+
opts[:s] ||= opts.delete(:size) if opts[:size]
|
23
29
|
|
24
30
|
# return empty pixel unless self
|
25
|
-
return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" if
|
31
|
+
return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" if opts[:i].to_s == ''
|
26
32
|
|
27
|
-
|
33
|
+
opts[:i] = opts[:i].sub(%r{^(\w+)://}, '')
|
28
34
|
prefix = $1 == 'https' ? 's' : 'p'
|
29
|
-
|
30
|
-
|
31
|
-
to_encode =
|
32
|
-
if opts
|
33
|
-
if opts.is_a?(Hash)
|
34
|
-
opts[:s] ||= opts.delete(:size) if opts[:size]
|
35
|
-
else
|
36
|
-
opts = { s: opts }
|
37
|
-
end
|
38
|
-
|
39
|
-
opts[:i] = image
|
40
|
-
opts.to_json
|
41
|
-
else
|
42
|
-
image
|
43
|
-
end
|
35
|
+
opts[:i] = prefix + opts[:i]
|
44
36
|
|
45
37
|
data = []
|
46
38
|
|
47
39
|
# add base
|
48
|
-
data.push Base64.urlsafe_encode64(
|
40
|
+
data.push Base64.urlsafe_encode64(opts.to_json).gsub(/=*\s*$/, '')
|
49
41
|
|
50
42
|
# add check
|
51
43
|
data.push Digest::SHA1.hexdigest(resizer_secret+data.first)[0,4]
|
52
44
|
|
53
45
|
# add extension
|
54
|
-
ext =
|
46
|
+
ext = opts[:i].split('.').last.to_s.downcase
|
55
47
|
ext = 'jpg' unless ['jpg', 'jpeg', 'gif', 'png', 'svg'].index(ext)
|
56
48
|
data.push '.%s' % ext
|
57
49
|
|