From 4e8f6ac5a537ab99f6b3f8b2848e5a4af503d532 Mon Sep 17 00:00:00 2001 From: solar Date: Sat, 18 Jun 2022 19:41:21 +0800 Subject: [PATCH] update readme --- README.md | 3 +++ canvas.go | 4 +++- captcha.go | 2 +- captcha_test.go | 5 ++++- previews/test_3.png | Bin 0 -> 4489 bytes 5 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 previews/test_3.png 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 0000000000000000000000000000000000000000..1923e84c8215644ffffcfa9e4e5642d5b9e7b63f GIT binary patch literal 4489 zcmYk9c{CJm7stm8V}`+G5~DDdkiD@cWM8t4EG1$Tl6A-XRL&pr1(_jArY_xqf4&%MtuCVDJP+)MxffW<&x`xXE|M}Ou!LV#y> z8OQMnNl-ioM2ZX6!0BB@NkFk@7Ly9x;%b_bmxV2PO;Uxn z%L!2!21gRy8*YZ^B3ynC_!TXqK=(>+D_kBfe*Y@{vu7Q-xp0AS!^Ni z|CyQFnSFcAl6<%^|MsD2)X8=p?a$0xo+rL9izE9{WYL1c+JWsVhrx6WOx_KIon}5n zu+K9Bdt6#~@b~0Vu$jsm1)adoc6RYU`c8Tmsd=@6uV5Jo_fpgw8g2=r7-7Qn1lI02 zxsnAqB!SJv@H|kMn(6R2CaWaAc=?frQ-q_Y`3^I5j(18O+j0w{ktnHA>nqFqFk0Rx`SHm zr)MH%dyaD&`&_3()2pM}!hjaG7O07n%eA@d9lx)7KP(t3aZvD(R z9FuwEGooaOc)9-OWNRw1`&j3BVI~E3hk|+bqI&SP>1u=Pu;8w&{^Pz*LZ{F%>Hrwo zmqn*0RreXL*!b(*7{Q@1!Ku6G;gMRv;q8M9U+H&R4gb>5H>xZzN?NJ?G5s>QC#NG| zV9~9J1`J7CS*!(yOb#zw`^GZK&>gBzbv-#gpj!zUdTe!Yp@B^`G;Ctv#=0-f4X116 zvpFnth25^Qe0EEjekp{Ip$nFc$_n?1{(kkw*gs0|Q-ipXM>;ExmWlj-e{akl+5ReF z2(W^Tz?9aFaI@&R^rFpVN~7kG+5L?3$9nth)j0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