illusionist 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/illusionist +2 -2
- data/lib/illusionist.rb +15 -11
- metadata +2 -2
data/bin/illusionist
CHANGED
@@ -8,8 +8,8 @@ options = {
|
|
8
8
|
:Port => '8080'
|
9
9
|
}
|
10
10
|
|
11
|
-
|
11
|
+
merlin = Illusionist.new
|
12
12
|
|
13
|
-
Rack::Handler::Thin.run(
|
13
|
+
Rack::Handler::Thin.run(merlin, options) do |server|
|
14
14
|
[:INT, :TERM].each { |sig| trap(sig) { server.stop } }
|
15
15
|
end
|
data/lib/illusionist.rb
CHANGED
@@ -30,27 +30,21 @@ class Illusionist
|
|
30
30
|
file_name = env["REQUEST_PATH"].split('.').first
|
31
31
|
extension = env["REQUEST_PATH"].split('.').last
|
32
32
|
illusion = "#{Dir.pwd}/illusions/#{file_name}_r#{width}x#{height}_#{mode}.#{extension}"
|
33
|
-
|
34
|
-
|
35
33
|
|
36
34
|
#create the illusion if nessicary
|
37
35
|
unless File.exists?(illusion)
|
38
36
|
#choose a resize function
|
39
|
-
resize_function =
|
40
|
-
when 'max' then :resize_to_fit
|
41
|
-
when 'pad' then :pad
|
42
|
-
when 'crop' then :resize_to_fill
|
43
|
-
when 'stretch' then :scale
|
44
|
-
else :resize_to_fill
|
45
|
-
end
|
37
|
+
resize_function = self.resize_function(mode)
|
46
38
|
|
47
39
|
#call the appropriate function
|
48
40
|
if resize_function == :pad #one of these things is not like the others
|
49
41
|
source = Image.read(full_path).first().resize_to_fit!(width, height)
|
42
|
+
#select the appropriate background color
|
43
|
+
background_color = source.opaque? ? 'white': 'Transparent'
|
50
44
|
target = Image.new(width, height) do
|
51
|
-
|
45
|
+
self.background_color = background_color
|
52
46
|
end
|
53
|
-
target.composite(source, CenterGravity,
|
47
|
+
target.composite(source, CenterGravity, OverCompositeOp).write(illusion)
|
54
48
|
else
|
55
49
|
Image.read(full_path).first().send(resize_function, width, height).write(illusion)
|
56
50
|
end
|
@@ -69,4 +63,14 @@ class Illusionist
|
|
69
63
|
[self.response_code, self.headers, self.body]
|
70
64
|
end
|
71
65
|
|
66
|
+
def resize_function(mode)
|
67
|
+
case mode
|
68
|
+
when 'max' then :resize_to_fit
|
69
|
+
when 'pad' then :pad
|
70
|
+
when 'crop' then :resize_to_fill
|
71
|
+
when 'stretch' then :scale
|
72
|
+
else :resize_to_fill
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
72
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: illusionist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|