modulepackage
0.0.0-20231031030829-4ae261e625ca
Repository: https://github.com/mzky/captcha.git
Documentation: pkg.go.dev
# README
本分支主要解决:
1.字母超出边界问题
2.公开img变量,以便保存成任何格式
3.增加保存jpg、png、gif文件函数
Package captcha provides an easy to use, unopinionated API for captcha generation.
Why another captcha generator?
I want a simple and framework-independent way to generate captcha. It also should be flexible, at least allow me to pick my favorite font.
install
go get github.com/mzky/captcha
usage
func handle(w http.ResponseWriter, r *http.Request) {
// create a captcha of 150x50px
data, _ := captcha.New(150, 50)
// session come from other library such as gorilla/sessions
session.Values["captcha"] = data.Text
session.Save(r, w)
// send image data to client
data.WriteImage(w)
}
documentation | example | font example
sample image
Compatibility
This package uses embed package from Go 1.16. If for some reasons you have to use pre 1.16 version of Go, reference pre 1.4 version of this module in your go.mod.
Contributing
If your found a bug, please contribute! see contributing.md for more detail.
License
# Functions
LoadFont let you load an external font.
LoadFontFromReader load an external font from an io.Reader interface.
New creates a new captcha.
NewCustomGenerator creates a new captcha based on a custom text generator.
NewMathExpr creates a new captcha.
# Type aliases
SetOption is a function that can be used to modify default options.