![](https://static.studygolang.com/190929/2ca57044cf6b9a1e7e24dbdbb05a9353.png)
gifCaptcha
gif 图形验证码
https://github.com/zxbit2011/gifCaptcha
丰富自定义设置
- 图片大小
- 多颜色
- 文字模式
- 文字数量
- 干扰强度
快速使用
> go get github.com/zxbit2011/gifCaptcha
示例代码
package main
import (
"github.com/zxbit2011/gifCaptcha"
"image/color"
"image/gif"
"net/http"
)
var captcha = gifCaptcha.New()
func main() {
//设置颜色
captcha.SetFrontColor(color.Black, color.RGBA{255, 0, 0, 255}, color.RGBA{0, 0, 255, 255}, color.RGBA{0, 153, 0, 255})
http.HandleFunc("/img", func(w http.ResponseWriter, r *http.Request) {
gifData, code := captcha.RangCaptcha()
println(code)
gif.EncodeAll(w, gifData)
})
http.ListenAndServe(":8080", nil)
}
- 运行示例
cd examples && go run main.go
- 浏览器预览
示例效果
黑白
![](https://static.studygolang.com/190929/105d326e5536b5d47122159a5c89415a.gif)
黑白
彩色
![](https://static.studygolang.com/190929/4f66acfbae40eaf962a9d4ee4df5ad06.gif)
彩色
感谢
https://github.com/afocus/captcha
有疑问加站长微信联系(非本文作者)
![](https://static.golangjob.cn/static/img/footer.png?imageView2/2/w/280)