验证码素材资源
GoCaptcha 预置了一些默认的内嵌素材资源,以Go文件格式存储;除此之外,你也可以根据定制的需求个化性去配置验证码
安装资源
shell
$ go get -u github.com/wenlng/go-captcha-assets@latest
$ go get -u github.com/wenlng/go-captcha-assets@latest
中文文本
go
import "github.com/wenlng/go-captcha-assets/bindata/chars"
func Demo() {
chars := chars.GetChineseChars()
}
import "github.com/wenlng/go-captcha-assets/bindata/chars"
func Demo() {
chars := chars.GetChineseChars()
}
字母+数字文本
go
import "github.com/wenlng/go-captcha-assets/bindata/chars"
func Demo() {
chars := chars.GetAlphaChars()
}
import "github.com/wenlng/go-captcha-assets/bindata/chars"
func Demo() {
chars := chars.GetAlphaChars()
}
字体
go
import "github.com/wenlng/go-captcha-assets/resources/fonts/fzshengsksjw"
import "github.com/wenlng/go-captcha-assets/resources/fonts/yrdzst"
func Demo() {
fonts, err := fzshengsksjw.GetFont()
if err != nil {
log.Fatalln(err)
}
// OR
fonts, err := yrdzst.GetFont()
if err != nil {
log.Fatalln(err)
}
}
import "github.com/wenlng/go-captcha-assets/resources/fonts/fzshengsksjw"
import "github.com/wenlng/go-captcha-assets/resources/fonts/yrdzst"
func Demo() {
fonts, err := fzshengsksjw.GetFont()
if err != nil {
log.Fatalln(err)
}
// OR
fonts, err := yrdzst.GetFont()
if err != nil {
log.Fatalln(err)
}
}
主图
go
import "github.com/wenlng/go-captcha-assets/resources/images"
func Demo() {
imgs, err := images.GetImages()
if err != nil {
log.Fatalln(err)
}
}
import "github.com/wenlng/go-captcha-assets/resources/images"
func Demo() {
imgs, err := images.GetImages()
if err != nil {
log.Fatalln(err)
}
}
图形
go
import "github.com/wenlng/go-captcha-assets/resources/shapes"
func Demo() {
shapeMaps, err := shapes.GetShapes()
if err != nil {
log.Fatalln(err)
}
}
import "github.com/wenlng/go-captcha-assets/resources/shapes"
func Demo() {
shapeMaps, err := shapes.GetShapes()
if err != nil {
log.Fatalln(err)
}
}
缩略图
go
import "github.com/wenlng/go-captcha-assets/resources/thumb"
func Demo() {
imgs, err := thumb.GetImages()
if err != nil {
log.Fatalln(err)
}
}
import "github.com/wenlng/go-captcha-assets/resources/thumb"
func Demo() {
imgs, err := thumb.GetImages()
if err != nil {
log.Fatalln(err)
}
}
贴图
go
import "github.com/wenlng/go-captcha-assets/resources/tiles"
func Demo() {
graphs, err := tiles.GetTiles()
if err != nil {
log.Fatalln(err)
}
// slide使用
var newGraphs = make([]*slide.GraphImage, 0, len(graphs))
for i := 0; i < len(graphs); i++ {
graph := graphs[i]
newGraphs = append(newGraphs, &slide.GraphImage{
OverlayImage: graph.OverlayImage,
MaskImage: graph.MaskImage,
ShadowImage: graph.ShadowImage,
})
}
}
import "github.com/wenlng/go-captcha-assets/resources/tiles"
func Demo() {
graphs, err := tiles.GetTiles()
if err != nil {
log.Fatalln(err)
}
// slide使用
var newGraphs = make([]*slide.GraphImage, 0, len(graphs))
for i := 0; i < len(graphs); i++ {
graph := graphs[i]
newGraphs = append(newGraphs, &slide.GraphImage{
OverlayImage: graph.OverlayImage,
MaskImage: graph.MaskImage,
ShadowImage: graph.ShadowImage,
})
}
}