/
captcha.go
69 lines (56 loc) · 1.34 KB
/
captcha.go
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
package cmds
import (
"fmt"
"html/template"
"log"
"net/http"
)
const (
dx = 150
dy = 50
)
func main() {
err := gocaptcha.ReadFonts("fonts", ".ttf")
if err != nil {
fmt.Println(err)
return
}
// gocaptcha.SetFontFamily(fontFils...)
//gocaptcha.SetFontFamily(
// "fonts/3Dumb.ttf",
// "fonts/DeborahFancyDress.ttf",
// "fonts/actionj.ttf",
// "fonts/chromohv.ttf",
// "fonts/D3Parallelism.ttf",
// "fonts/Flim-Flam.ttf",
// "fonts/KREMLINGEORGIANI3D.ttf",
// )
http.HandleFunc("/", Index)
http.HandleFunc("/get/", Get)
fmt.Println("服务已启动...")
err = http.ListenAndServe(":8800", nil)
if err != nil {
log.Fatal(err)
}
}
func Index(w http.ResponseWriter, r *http.Request) {
t, err := template.ParseFiles("tpl/index.html")
if err != nil {
log.Fatal(err)
}
t.Execute(w, nil)
}
func Get(w http.ResponseWriter, r *http.Request) {
captchaImage, err := gocaptcha.NewCaptchaImage(dx, dy, gocaptcha.RandLightColor())
captchaImage.DrawNoise(gocaptcha.CaptchaComplexLower)
captchaImage.DrawTextNoise(gocaptcha.CaptchaComplexLower)
captchaImage.DrawText(gocaptcha.RandText(4))
//captchaImage.Drawline(3);
captchaImage.DrawBorder(gocaptcha.ColorToRGB(0x17A7A7A))
captchaImage.DrawSineLine()
//captchaImage.DrawHollowLine()
if err != nil {
fmt.Println(err)
}
captchaImage.SaveImage(w, gocaptcha.ImageFormatJpeg)
}