45 lines
956 B
Go
45 lines
956 B
Go
package initialize
|
|
|
|
import (
|
|
"github.com/wenlng/go-captcha-assets/resources/images"
|
|
"github.com/wenlng/go-captcha-assets/resources/tiles"
|
|
"github.com/wenlng/go-captcha/v2/slide"
|
|
)
|
|
|
|
// NewSlideCaptcha 初始化滑动验证码
|
|
func NewSlideCaptcha() slide.Captcha {
|
|
builder := slide.NewBuilder(
|
|
// slide.WithGenGraphNumber(2),
|
|
slide.WithEnableGraphVerticalRandom(true),
|
|
)
|
|
|
|
// background images
|
|
imgs, err := images.GetImages()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
graphs, err := tiles.GetTiles()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
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,
|
|
})
|
|
}
|
|
|
|
// set resources
|
|
builder.SetResources(
|
|
slide.WithGraphImages(newGraphs),
|
|
slide.WithBackgrounds(imgs),
|
|
)
|
|
|
|
return builder.Make()
|
|
}
|