diff --git a/faq_test.go b/faq_test.go new file mode 100644 index 0000000..c13ebcc --- /dev/null +++ b/faq_test.go @@ -0,0 +1,27 @@ +package base64Captcha + +import "testing" + +func TestHandlerCaptchaGenerate(t *testing.T) { + s := DefaultMemStore + + driver := &DriverString{ + Height: 80, + Width: 240, + NoiseCount: 10, + ShowLineOptions: 10, + Length: 10, + Source: "axclajsdlfkjalskjdglasdg", + BgColor: nil, + Fonts: nil, + } + + c := NewCaptcha(driver, s) + + id, _, err := c.Generate() + if err != nil { + t.Fatalf("some error: %s", err) + } + + t.Logf("id: %s", id) +} diff --git a/fonts.go b/fonts.go index ba5fb1c..98e56f4 100644 --- a/fonts.go +++ b/fonts.go @@ -49,6 +49,12 @@ func loadFontsByNames(assetFontNames []string) []*truetype.Font { //randFontFrom choose random font family.选择随机的字体 func randFontFrom(fonts []*truetype.Font) *truetype.Font { fontCount := len(fonts) + + if fontCount == 0 { + //loading default fonts + fonts = fontsAll + fontCount = len(fontsAll) + } index := rand.Intn(fontCount) return fonts[index] }