-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption.go
More file actions
133 lines (118 loc) · 3.09 KB
/
Copy pathoption.go
File metadata and controls
133 lines (118 loc) · 3.09 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package captcha
import "image/color"
const (
Lowercase CharSet = "abcdefghijklmnopqrstuvwxyz"
Uppercase CharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Alphabetic CharSet = Lowercase + Uppercase
Numeric CharSet = "0123456789"
Hex CharSet = Numeric + "abcdef"
LowerNumeric CharSet = Lowercase + Numeric
UpperNumeric CharSet = Uppercase + Numeric
AlphaNumeric CharSet = Alphabetic + Numeric
AlphaNumericWithoutConfusion CharSet = "ABCDEFGHKLMNPQRSTUVWXYZabcdefghkmnpqsuvwxyz23456789"
)
type Option func(*Captcha)
// WithSize sets the size of the captcha image.
//
// Default: 140x50
func WithSize(width, height int) Option {
return func(c *Captcha) {
c.width = width
c.height = height
}
}
// WithCharSet sets the character set used to generate the captcha.
//
// Default: AlphaNumeric
func WithCharSet(charSet CharSet) Option {
return func(c *Captcha) {
c.charSet = charSet
}
}
// WithLength sets the minimum and maximum length of the captcha.
//
// Default: 4, 4
func WithLength(minLength, maxLength int) Option {
return func(c *Captcha) {
c.minLength = minLength
c.maxLength = maxLength
}
}
// WithFont sets the font used to generate the captcha.
//
// Default: nil, 40
func WithFont(path string, size float64) Option {
return func(c *Captcha) {
c.fontPath = path
c.fontSize = size
}
}
// WithBackground sets the background color of the captcha.
//
// Default: color.White
func WithBackground(background color.Color) Option {
return func(c *Captcha) {
c.background = background
}
}
// WithForeground sets the foreground color of the captcha.
//
// Default: color.Black
func WithForeground(foreground color.Color) Option {
return func(c *Captcha) {
c.foreground = foreground
}
}
// WithSpacing sets the spacing between characters.
//
// Default: 1.0, 1.0
func WithSpacing(minSpacing, maxSpacing float64) Option {
return func(c *Captcha) {
c.minSpacing = minSpacing
c.maxSpacing = maxSpacing
}
}
// WithRotation sets the rotation angle of characters.
//
// Default: 0.0, 0.0
func WithRotation(minRotation, maxRotation float64) Option {
return func(c *Captcha) {
c.minRotation = minRotation
c.maxRotation = maxRotation
}
}
// WithScale sets the scaling factor of characters.
//
// Default: 1.0, 1.0
func WithScale(minScale, maxScale float64) Option {
return func(c *Captcha) {
c.minScale = minScale
c.maxScale = maxScale
}
}
// WithDistortion sets the distortion factor of characters.
//
// Default: 0.0, 0.0
func WithDistortion(minDistortion, maxDistortion float64) Option {
return func(c *Captcha) {
c.minDistortion = minDistortion
c.maxDistortion = maxDistortion
}
}
// WithLines sets the number of lines to draw on the captcha.
//
// Default: 3, 7
func WithLines(minLines, maxLines int) Option {
return func(c *Captcha) {
c.minLines = minLines
c.maxLines = maxLines
}
}
// WithNoise sets the level of noise to add to the captcha.
//
// Default: 0.1
func WithNoise(level float64) Option {
return func(c *Captcha) {
c.noiseLevel = level
}
}