-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.rb
71 lines (67 loc) · 2.05 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
module Captcha
class Config
def initialize(options={})
@@options = {
:colors => {
:background => '#1B1C20',
:font => '#7385C5'
},
# number of captcha images to generate
:count => 500,
:destination => File.expand_path(
(defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/" : '') +
"public/images/captchas"
),
:dimensions => {
# canvas height (px)
:height => 31,
# canvas width (px)
:width => 90
},
:generate_every => 24 * 60 * 60,
# http://www.imagemagick.org/RMagick/doc/image2.html#implode
:implode => 0.2,
:letters => {
# text baseline (px)
:baseline => 24,
# number of letters in captcha
:count => 6,
:ignore => ['a','e','i','o','u','l','j','q'],
# font size (pts)
:points => 34,
# width of a character (used to decrease or increase space between characters) (px)
:width => 14
},
:ttf => File.expand_path("#{File.dirname(__FILE__)}/../../resources/captcha.ttf"),
# http://www.imagemagick.org/RMagick/doc/image3.html#wave
:wave => {
# range is used for randomness (px)
:wavelength => (20..70),
# distance between peak and valley of sin wave (px)
:amplitude => 3
}
}.merge(options)
end
def self.captchas_ordered_by_modified
return unless @@options
files_modified = Dir["#{@@options[:destination]}/*.jpg"].collect do |file|
[ file, File.mtime(file) ]
end
# Youngest to oldest
files_modified.sort! { |a, b| b[1] <=> a[1] }
files_modified.collect { |f| f[0] }
end
def self.codes
self.captchas_ordered_by_modified.collect do |f|
File.basename f, '.jpg'
end
end
def self.options
@@options
end
def self.last_modified
youngest = self.captchas_ordered_by_modified.first
youngest ? File.mtime(youngest) : nil
end
end
end