https://github.com/xkeyideal/captcha
Go package captcha generation and verification of image, Refer from https://github.com/dchest/captcha. Use captcha pool generation
https://github.com/xkeyideal/captcha
captcha-generator channel context go goroutine image-captcha
Last synced: about 1 month ago
JSON representation
Go package captcha generation and verification of image, Refer from https://github.com/dchest/captcha. Use captcha pool generation
- Host: GitHub
- URL: https://github.com/xkeyideal/captcha
- Owner: xkeyideal
- License: mit
- Created: 2017-05-18T03:29:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-11-29T09:05:47.000Z (over 4 years ago)
- Last Synced: 2024-06-20T04:52:17.400Z (almost 2 years ago)
- Topics: captcha-generator, channel, context, go, goroutine, image-captcha
- Language: Go
- Size: 16.6 KB
- Stars: 30
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
Package captcha
=====================
Package captcha implements generation and verification of image
CAPTCHAs.
A captcha solution is the sequence of digits 0-9 with the defined length.
An image representation is a PNG-encoded or JPEG-encoded image with the solution printed on
it in such a way that makes it hard for computers to solve it using OCR.
This package doesn't require external files or libraries to generate captcha
representations; it is self-contained.
Package code refer from [dchest/captcha](https://github.com/dchest/captcha)
Advantages:
1. High-Performance:Generation captcha use goroutine + channel, get captcha ready in advance by channel
2. Change panic to error, avoid runtime panic
3. Not inline store interface, can use any store method such as Redis, Memcache, Memory and so on after get captcha image
4. Use uuid instead of original random id avoid conflict
5. Add Context to control generate captcha goroutine, can stop generate programming active
`go get github.com/xkeyideal/captcha`
Examples
--------

Functions
---------
### func NewCaptchaPool
NewCaptchaPool(width, height, wordLength, poolsize, parallelNum, imageType int)
Creates a new captcha pool
1. width, height: image's width and height
2. wordLength: generate words' length
3. poolsize: buffer size
4. parallelNum: goroutine number
5. imageType: PNG or JPEG
### func Stop
func (p *CaptchaPool) Stop()
Stop CaptchaPool active
Usage
--------
```go
type CaptchaBody struct {
Id string
Data *bytes.Buffer
Val []byte
}
CaptchaPool = pool.NewCaptchaPool(240, 80, 6, 10, 1, 2)
captchaBody := CaptchaPool.GetImage()
CaptchaPool.Stop()
```
See detail in file [captcha.go](https://github.com/xkeyideal/captcha/blob/master/captcha.go)
Golang context can't control goroutine channel will deadlock by using sync.WaitGroup to wait all goroutine return and close channels.