game_sync/common/imagecode.go

28 lines
692 B
Go

package common
import (
"github.com/mojocn/base64Captcha"
"strings"
)
var ImageStore = base64Captcha.DefaultMemStore
func ImageCode() (b64s string, answer string, err error) {
driver := &base64Captcha.DriverString{
Height: 50,
Width: 100,
NoiseCount: 0,
ShowLineOptions: base64Captcha.OptionShowHollowLine | base64Captcha.OptionShowSlimeLine,
Length: 5,
Source: "123456789qwertyuiopasdfghjklzxcvb",
}
var id string
c := base64Captcha.NewCaptcha(driver, ImageStore)
id, b64s, answer, err = c.Generate()
ImageStore.Verify(id, answer, true)
b64s = strings.TrimPrefix(b64s, "data:image/png;base64,")
return b64s, answer, err
}