struggle 1.7.2 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/struggle/font/font.ttf +0 -0
- data/lib/struggle/vcode.rb +26 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 286dc699ce29f3c5d20c0b29924cb1456664468a
|
4
|
+
data.tar.gz: 2f828400f7234ec0f8c87f5b877bdb71f28239c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2115f3e858f39ce81572743fa36f2cce32fb8a4cae03253dff8780209c0e8a2fff5498d6630035a102fb6c9af36c87b597ff5e6dd8b2880ce5934b38540cc8b
|
7
|
+
data.tar.gz: 97a8e221c0020a5d4062e9bf943b051a0602249577c02cdb8a7cc2026f50107965296f64ba41803df936be77fbed6a772139d72098c84de02fdd6829deb966e2
|
Binary file
|
data/lib/struggle/vcode.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
+
#first gem 'rmagick'
|
1
2
|
module Struggle
|
2
3
|
class Vcode
|
4
|
+
#controller
|
5
|
+
#def getcode
|
6
|
+
# vcode = Vcode.getvcode
|
7
|
+
# session[:code]=vcode[:code]
|
8
|
+
# send_data vcode[:img], content_type: 'image/jpeg', disposition: 'inline'
|
9
|
+
#end
|
10
|
+
#view
|
11
|
+
# <img src="/getcode">
|
12
|
+
#Vcode.getvcode(90,40,24)
|
13
|
+
#w宽,h高,fontsize字体大小
|
14
|
+
#返回json类型
|
3
15
|
def self.getvcode(w=90, h=40, fontsize=24)
|
16
|
+
#创建画布
|
4
17
|
img = Magick::Image.new(w, h) {
|
5
18
|
self.background_color = 'white'
|
6
19
|
self.format="JPG"
|
@@ -8,21 +21,29 @@ module Struggle
|
|
8
21
|
text= Magick::Draw.new
|
9
22
|
text.pointsize = fontsize
|
10
23
|
text.kerning = -1
|
24
|
+
text.font("font/font.ttf")
|
25
|
+
text.font_weight(900)
|
11
26
|
text.fill('blue')
|
27
|
+
#随机文字
|
12
28
|
code=""
|
13
29
|
4.times { code << (97 + rand(26)).chr }
|
30
|
+
#设置文字
|
14
31
|
text.text(rand(w/2-5), h/2-5+ rand(h/2), code)
|
32
|
+
#随机直线
|
15
33
|
for i in 1..rand(4)
|
16
|
-
text.line(rand(w), rand(h), rand(w), rand(h))
|
34
|
+
text.line(rand(w), rand(h), rand(w), rand(h)) #直线
|
17
35
|
end
|
18
36
|
text.fill('blue')
|
19
|
-
|
20
|
-
|
21
|
-
|
37
|
+
#燥点
|
38
|
+
# for i in 1..280
|
39
|
+
# text.point(rand(w), rand(h))
|
40
|
+
# end
|
22
41
|
text.draw(img)
|
23
|
-
|
42
|
+
#模糊
|
43
|
+
# img = img.sketch(0, 10, 50)
|
24
44
|
#扭曲
|
25
45
|
img = img.wave(5.5, 50)
|
46
|
+
#返回图片数据流
|
26
47
|
{img: img.to_blob, code: code}
|
27
48
|
end
|
28
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: struggle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lean
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/struggle.rb
|
50
50
|
- lib/struggle/concerns/int_extend.rb
|
51
51
|
- lib/struggle/concerns/string_extend.rb
|
52
|
+
- lib/struggle/font/font.ttf
|
52
53
|
- lib/struggle/func.rb
|
53
54
|
- lib/struggle/logistic.rb
|
54
55
|
- lib/struggle/pager.rb
|
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
version: '0'
|
78
79
|
requirements: []
|
79
80
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.4.
|
81
|
+
rubygems_version: 2.4.8
|
81
82
|
signing_key:
|
82
83
|
specification_version: 4
|
83
84
|
summary: struggle!
|