diff --git a/README.md b/README.md index ed93d36..0e82715 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ golang 实现普通验证码,同时支持中文汉字点击行为验证码 ![](./previews/test_2.png) +![](./previews/test_3.png) + + ## Quick Start 使用 *普通验证码* diff --git a/canvas.go b/canvas.go index 5fbeec9..102d264 100644 --- a/canvas.go +++ b/canvas.go @@ -147,6 +147,7 @@ func (c *Canvas) getFontPostions(text string) []Point { chCount := utf8.RuneCountInString(text) var points []Point + if c.Config.Style == CaptchaStyle_Normal { padding := c.Config.FontSize / 2 @@ -164,6 +165,7 @@ func (c *Canvas) getFontPostions(text string) []Point { for i := 0; i < chCount; i++ { p := c.randomFontPosition(56) + points = append(points, p) } } @@ -417,4 +419,4 @@ func (c *Canvas) DrawCircle(xc, yc, r int, fill bool, cc color.Color) { } x++ } -} \ No newline at end of file +} diff --git a/captcha.go b/captcha.go index 2b9cf31..82481e1 100644 --- a/captcha.go +++ b/captcha.go @@ -128,7 +128,7 @@ func (cp *Captcha) GenCaptchaImage(text string) (CaptchaResult, error) { result.ImageBase64 = fmt.Sprintf("data:%s;base64,%s", "image/png", base64.StdEncoding.EncodeToString(imageBytes)) result.Text = text - // writeImageFile("./previews/test.png", imageBytes) + writeImageFile("./previews/test.png", imageBytes) return result, nil } diff --git a/captcha_test.go b/captcha_test.go index c9641e1..429b97e 100644 --- a/captcha_test.go +++ b/captcha_test.go @@ -27,8 +27,11 @@ func TestGenGenBehaviorCaptcha(t *testing.T) { cpt := NewCaptcha(260, 100) cpt.SetBackgroundColor(color.RGBA{R: uint8(20), G: uint8(8), B: uint8(100), A: uint8(255)}) - // cpt.Config.Style = CaptchaStyle_Behavior + cpt.Config.Style = CaptchaStyle_Behavior cpt.Config.MaxRotate = 20 + + t.Logf("cpt.Config: %+v ", cpt.Config) + result, err := cpt.GenBehaviorCNCaptcha() t.Logf("GenCaptchaImage: %+v %+v", result, err) } diff --git a/previews/test_3.png b/previews/test_3.png new file mode 100644 index 0000000..1923e84 Binary files /dev/null and b/previews/test_3.png differ