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
|
# File 'lib/struggle/code.rb', line 15
def self.getcode(w=90, h=40, fontsize=24, wave=5.5)
img = Magick::Image.new(w, h) {
self.background_color = 'white'
self.format="JPG"
}
text= Magick::Draw.new
text.pointsize = fontsize
text.kerning = -1
text.font("/font/ARIALNBI.TTF")
text.font_weight(200)
text.fill('blue')
code=""
4.times { code << (97 + rand(26)).chr }
text.text(rand(w/2-5), h/2 + rand(-2..2), code)
for i in 1..rand(5)
text.line(rand(w), rand(h), rand(w), rand(h)) end
text.fill('blue')
for i in 1..20
text.point(rand(w), rand(h))
end
text.draw(img)
img = img.wave(wave, 70)
{img: img.to_blob, code: code}
end
|