Initial captcha image generation
This commit is contained in:
parent
104fd180ab
commit
e411553db4
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.22.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/fogleman/gg v1.3.0 // indirect
|
github.com/fogleman/gg v1.3.0
|
||||||
github.com/glebarez/go-sqlite v1.22.0 // indirect
|
github.com/glebarez/go-sqlite v1.22.0 // indirect
|
||||||
github.com/go-telegram/bot v1.5.0 // indirect
|
github.com/go-telegram/bot v1.5.0 // indirect
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"image/color"
|
||||||
|
|
||||||
|
"github.com/fogleman/gg"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
res embed.FS
|
||||||
|
)
|
||||||
|
|
||||||
|
func GenCaptcha() {
|
||||||
|
dc := gg.NewContext(400, 300)
|
||||||
|
gd := gg.NewLinearGradient(0, 0, 400, 300)
|
||||||
|
gd.AddColorStop(0, color.RGBA{189, 24, 229, 255})
|
||||||
|
gd.AddColorStop(1, color.RGBA{27, 21, 123, 255})
|
||||||
|
dc.SetFillStyle(gd)
|
||||||
|
dc.DrawRectangle(0, 0, 400, 300)
|
||||||
|
dc.Fill()
|
||||||
|
dc.SetRGBA(0, 0, 0, 0.05)
|
||||||
|
dc.SetLineWidth(27)
|
||||||
|
for i := 0.0; i < 20; i += 1 {
|
||||||
|
dc.DrawLine(i * 70, -100, i * 70 - 500, 400)
|
||||||
|
dc.Stroke()
|
||||||
|
}
|
||||||
|
dc.SavePNG("grad.png")
|
||||||
|
}
|
|
@ -148,7 +148,6 @@ func handlePrivateStartCaptcha(ctx context.Context, b *bot.Bot, u *models.Update
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if captcha.CorrectAnswer == 0 {
|
if captcha.CorrectAnswer == 0 {
|
||||||
captcha.CorrectAnswer = 42
|
captcha.CorrectAnswer = 42
|
||||||
msg, err := b.SendMessage(ctx, &bot.SendMessageParams{
|
msg, err := b.SendMessage(ctx, &bot.SendMessageParams{
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
GenCaptcha()
|
||||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue