glebtv-simple_captcha 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/simple_captcha/image.rb +13 -15
- data/lib/simple_captcha/middleware.rb +6 -1
- data/lib/simple_captcha/version.rb +1 -1
- data/lib/simple_captcha.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 449ca80c41d5dedc86f12d03538f9645a9dd7e45
|
4
|
+
data.tar.gz: 1a903f97a8f9101aeb807985ba229a252cf9969d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd15460ff8d8ae922861b09fd920cf3fc4d6f8b6dd62ff9a3043085aeb11fae2157ffe89436e6e8ccaff26a1e17193d2cceaa7440a3b37d19c176ea057d946ed
|
7
|
+
data.tar.gz: 25670d30d876c24d618c04513a1ee6955e4a4338e5c79a89dc7306783517c10e90e0f904b9f533b134a97c20e33ffd0172d159f8893c64cfe4b3ccd2df2a8c86
|
data/lib/simple_captcha/image.rb
CHANGED
@@ -4,14 +4,10 @@ module SimpleCaptcha #:nodoc
|
|
4
4
|
|
5
5
|
mattr_accessor :image_styles
|
6
6
|
@@image_styles = {
|
7
|
-
'
|
8
|
-
'
|
9
|
-
'
|
10
|
-
'
|
11
|
-
'distorted_black' => ['-fill darkblue', '-edge 10', '-background white'],
|
12
|
-
'all_black' => ['-fill darkblue', '-edge 2', '-background white'],
|
13
|
-
'charcoal_grey' => ['-fill darkblue', '-charcoal 5', '-background white'],
|
14
|
-
'almost_invisible' => ['-fill red', '-solarize 50', '-background white']
|
7
|
+
'simply_red' => ['-alpha set', '-fill darkred', '-background white', '-size 200x50', 'xc:white'],
|
8
|
+
'simply_green' => ['-alpha set', '-fill darkgreen', '-background white', '-size 200x50', 'xc:white'],
|
9
|
+
'simply_blue' => ['-alpha set', '-fill darkblue', '-background white', '-size 200x50', 'xc:white'],
|
10
|
+
'red' => ['-alpha set', '-fill \#A5A5A5', '-background \#800E19', '-size 245x60', 'xc:\#800E19'],
|
15
11
|
}
|
16
12
|
|
17
13
|
DISTORTIONS = ['low', 'medium', 'high']
|
@@ -68,10 +64,10 @@ module SimpleCaptcha #:nodoc
|
|
68
64
|
params = ImageHelpers.image_params(SimpleCaptcha.image_style).dup
|
69
65
|
else
|
70
66
|
params = ImageHelpers.image_params_from_color(SimpleCaptcha.image_color).dup
|
67
|
+
params << "-size #{SimpleCaptcha.image_size} xc:transparent"
|
71
68
|
end
|
72
|
-
|
73
|
-
params << "-size #{SimpleCaptcha.image_size} xc:transparent"
|
74
69
|
params << "-gravity \"Center\""
|
70
|
+
|
75
71
|
psz = SimpleCaptcha.pointsize
|
76
72
|
if params.join(' ').index('-pointsize').nil?
|
77
73
|
params << "-pointsize #{psz}"
|
@@ -80,24 +76,26 @@ module SimpleCaptcha #:nodoc
|
|
80
76
|
dst = Tempfile.new(RUBY_VERSION < '1.9' ? 'simple_captcha.png' : ['simple_captcha', '.png'], SimpleCaptcha.tmp_path)
|
81
77
|
dst.binmode
|
82
78
|
text.split(//).each_with_index do |letter, index|
|
83
|
-
i = -(
|
79
|
+
i = -(2 * psz) + (index * 0.7 * psz) + rand(-3..3)
|
84
80
|
params << "-draw \"translate #{i},#{rand(-3..3)} skewX #{rand(-15..15)} gravity center text 0,0 '#{letter}'\" "
|
85
81
|
end
|
86
82
|
|
87
83
|
params << "-wave #{amplitude}x#{frequency}"
|
88
84
|
|
89
|
-
(
|
90
|
-
params
|
85
|
+
unless params.join(' ').index('-size').nil?
|
86
|
+
size = params.join(' ').match '-size (\d+)x(\d+)'
|
87
|
+
(1..SimpleCaptcha.wave_count).each do |i|
|
88
|
+
params << "-draw \"polyline #{rand(size[1].to_i)},#{rand(size[2].to_i)} #{rand(size[1].to_i)},#{rand(size[2].to_i)}\""
|
89
|
+
end
|
91
90
|
end
|
92
91
|
|
93
92
|
params << "\"#{File.expand_path(dst.path)}\""
|
94
|
-
|
93
|
+
|
95
94
|
SimpleCaptcha::Utils::run("convert", params.join(' '))
|
96
95
|
|
97
96
|
dst.close
|
98
97
|
|
99
98
|
File.expand_path(dst.path)
|
100
|
-
#dst
|
101
99
|
end
|
102
100
|
end
|
103
101
|
end
|
@@ -46,7 +46,12 @@ module SimpleCaptcha
|
|
46
46
|
options[:filename] ||= File.basename(path) unless options[:url_based_filename]
|
47
47
|
|
48
48
|
status = options[:status] || 200
|
49
|
-
headers = {
|
49
|
+
headers = {
|
50
|
+
"Content-Disposition" => "#{options[:disposition]}; filename='#{options[:filename]}'",
|
51
|
+
# "Content-Type" => options[:type],
|
52
|
+
'Content-Transfer-Encoding' => 'binary',
|
53
|
+
'Cache-Control' => 'private'
|
54
|
+
}
|
50
55
|
response_body = [File.open(path, "rb").read]
|
51
56
|
File.delete(path)
|
52
57
|
|
data/lib/simple_captcha.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glebtv-simple_captcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GlebTv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|