Files
mindoc/vendor/github.com/lifei6671/gocaptcha/README.md
Minho 8441b7e338 1、修复匿名访问时没有搜索结果的BUG
2、新增windows和Linux安装教程
2017-05-05 10:30:19 +08:00

66 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# gocaptcha
一个简单的Go语言实现的验证码
##图片实例
![image](https://raw.githubusercontent.com/lifei6671/gocaptcha/master/example/image_1.jpg)
![image](https://raw.githubusercontent.com/lifei6671/gocaptcha/master/example/image_2.jpg)
![image](https://raw.githubusercontent.com/lifei6671/gocaptcha/master/example/image_3.jpg)
![image](https://raw.githubusercontent.com/lifei6671/gocaptcha/master/example/image_4.jpg)
##简介
基于Golang实现的图片验证码生成库可以实现随机字母个数随机直线随机噪点等。可以设置任意多字体每个验证码随机选一种字体展示。
##实例
####使用:
```
go get github.com/lifei6671/gocaptcha/
```
####使用的类库
```
go get github.com/golang/freetype
go get github.com/golang/freetype/truetype
go get golang.org/x/image
```
天朝可以去 http://www.golangtc.com/download/package 或 https://gopm.io 下载
####代码
具体实例可以查看example目录有生成的验证码图片。
```
func Get(w http.ResponseWriter, r *http.Request) {
//初始化一个验证码对象
captchaImage,err := gocaptcha.NewCaptchaImage(dx,dy,gocaptcha.RandLightColor());
//画上三条随机直线
captchaImage.Drawline(3);
//画边框
captchaImage.DrawBorder(gocaptcha.ColorToRGB(0x17A7A7A));
//画随机噪点
captchaImage.DrawNoise(gocaptcha.CaptchaComplexHigh);
//画随机文字噪点
captchaImage.DrawTextNoise(gocaptcha.CaptchaComplexLower);
//画验证码文字可以预先保持到Session种或其他储存容器种
captchaImage.DrawText(gocaptcha.RandText(4));
if err != nil {
fmt.Println(err)
}
//将验证码保持到输出流种可以是文件或HTTP流等
captchaImage.SaveImage(w,gocaptcha.ImageFormatJpeg);
}
```