Debian Codegraph @

tests/inputs/issues/784/src/net/companies/captcha.cs

raw
1 "http://smalltalk.gnu.org/blog/bonzinip/captcha-simplest-gst-external-module"
2 DLD addModule: 'GD'.
3 FileStream fileIn: 'GST_DIR/share/smalltalk/GD/GD.st'.
4
5 "A useful method... (will be in 3.0.1)"
6 SequenceableCollection extend [
7 atRandom [
8 ^self at: (Random between: 1 and: self size)
9 ]
10 ]
11
12 "Make a four character captcha."
13 fontPath := '/usr/share/fonts/bitstream-vera/Vera.ttf'.
14 authChars := '0123456789'.
15 authChars := authChars, 'abcdefghijklmnopqrstuvwxyz'.
16 authChars := authChars, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
17
18 authString := String streamContents: [ :s |.
19 4 timesRepeat: [ s nextPut: authChars atRandom ]].
20
21 GD
22 imageString: authString
23 font: fontPath
24 foreground: #[255 255 255]
25 background: #[0 0 0]
26 size: 40
27 to: 'captcha.png'.