enhance 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/enhance/enhancer.rb +17 -4
- data/lib/enhance/version.rb +1 -1
- metadata +45 -75
data/lib/enhance/enhancer.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
|
2
2
|
class Enhance::Enhancer
|
3
3
|
|
4
|
+
Geometry = /^(?<geometry>(?<width>\d+)?x?(?<height>\d+)?([\>\<\@\%^!])?)(?<filter>sample)?$/
|
5
|
+
|
4
6
|
def initialize app, root, options = {}
|
5
7
|
@app = app
|
6
|
-
@extensions = options[:extensions] || %w( jpg png )
|
8
|
+
@extensions = options[:extensions] || %w( jpg png jpeg gif )
|
7
9
|
@routes = options[:routes] || %w( images )
|
8
10
|
@folders = options[:folders] || [File.join(root, "public")]
|
9
11
|
@quality = options[:quality] || 100
|
@@ -25,7 +27,10 @@ class Enhance::Enhancer
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def _call env, matches
|
28
|
-
request = @folders.collect_first
|
30
|
+
request = @folders.collect_first do |f|
|
31
|
+
f = File.join(f, matches['filename'])
|
32
|
+
File.exists?(f) ? f : nil
|
33
|
+
end
|
29
34
|
|
30
35
|
if request && (filename = convert(request, matches['filename'], CGI.unescape(matches['geometry']))) && filename.gsub!(@file_root, '')
|
31
36
|
env["PATH_INFO"] = filename
|
@@ -38,7 +43,7 @@ class Enhance::Enhancer
|
|
38
43
|
# Finds the image and resizes it if needs be
|
39
44
|
def convert path, filename, geometry
|
40
45
|
# Extract the width and height
|
41
|
-
if sizes = geometry.match(
|
46
|
+
if sizes = geometry.match(Geometry)
|
42
47
|
w, h = sizes['width'], sizes['height']
|
43
48
|
ow, oh = original_size path
|
44
49
|
|
@@ -58,7 +63,15 @@ class Enhance::Enhancer
|
|
58
63
|
def resize source, destination, geometry
|
59
64
|
FileUtils.mkdir_p File.dirname(destination)
|
60
65
|
|
61
|
-
|
66
|
+
match = geometry.match Geometry
|
67
|
+
|
68
|
+
method = match['filter'] || 'resize'
|
69
|
+
|
70
|
+
unless File.exists?(destination) && File.mtime(destination) > File.mtime(source)
|
71
|
+
command = "#{@command_path}convert \"#{source}\" -#{method} \"#{match['geometry']}\" -quality #{@quality} \"#{destination}\""
|
72
|
+
puts command
|
73
|
+
`#{command}`
|
74
|
+
end
|
62
75
|
|
63
76
|
destination
|
64
77
|
end
|
data/lib/enhance/version.rb
CHANGED
metadata
CHANGED
@@ -1,113 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: enhance
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 6
|
10
|
-
version: 0.0.6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Guillaume Malette
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-08-26 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rack
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2169505760 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: utilities
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: *2169505760
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: utilities
|
27
|
+
requirement: &2169505280 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
47
33
|
type: :runtime
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: rack-test
|
51
34
|
prerelease: false
|
52
|
-
|
35
|
+
version_requirements: *2169505280
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rack-test
|
38
|
+
requirement: &2169504820 !ruby/object:Gem::Requirement
|
53
39
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
version: "0"
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
61
44
|
type: :development
|
62
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2169504820
|
63
47
|
description: Middleware to "enhance" and resize images on the fly.
|
64
48
|
email: gmalette@gmail.com
|
65
49
|
executables: []
|
66
|
-
|
67
50
|
extensions: []
|
68
|
-
|
69
51
|
extra_rdoc_files: []
|
70
|
-
|
71
|
-
files:
|
52
|
+
files:
|
72
53
|
- README
|
73
54
|
- enhance.gemspec
|
74
55
|
- lib/enhance.rb
|
75
56
|
- lib/enhance/enhancer.rb
|
76
57
|
- lib/enhance/urlhelper.rb
|
77
58
|
- lib/enhance/version.rb
|
78
|
-
|
79
|
-
homepage: ""
|
59
|
+
homepage: ''
|
80
60
|
licenses: []
|
81
|
-
|
82
61
|
post_install_message:
|
83
62
|
rdoc_options: []
|
84
|
-
|
85
|
-
require_paths:
|
63
|
+
require_paths:
|
86
64
|
- lib
|
87
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
66
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
|
93
|
-
|
94
|
-
- 0
|
95
|
-
version: "0"
|
96
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
72
|
none: false
|
98
|
-
requirements:
|
99
|
-
- -
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
|
102
|
-
segments:
|
103
|
-
- 0
|
104
|
-
version: "0"
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
105
77
|
requirements: []
|
106
|
-
|
107
78
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.
|
79
|
+
rubygems_version: 1.8.6
|
109
80
|
signing_key:
|
110
81
|
specification_version: 3
|
111
82
|
summary: Image resizing on the fly
|
112
83
|
test_files: []
|
113
|
-
|