Documentation ¶
Overview ¶
*
- @Author Awen
- @Description Captcha Config
- @Date 2021/7/18
- @Email wengaolng@gmail.com *
*
- @Author Awen
- @Description Captcha Draw
- @Date 2021/7/18
- @Email wengaolng@gmail.com *
*
- @Author Awen
- @Description Captcha Palette
- @Date 2021/7/18
- @Email wengaolng@gmail.com *
Index ¶
- Constants
- func Child(path string) []string
- func EncodeB64string(img image.Image) string
- func GenerateKey(str string) (string, error)
- func GetCaptchaDefaultChars() []string
- func HexToRgb(hex string) (int64, int64, int64)
- func InArrayWithStr(items []string, s string) bool
- func IsChineseChar(str string) bool
- func LenChineseChar(str string) int
- func Md5ToString(str string) string
- func ParseHexColor(s string) (c color.RGBA, err error)
- func PathExists(path string) (bool, error)
- func RandFloat(min, max int) float64
- func RandInt(min, max int) (result int)
- func RgbToHex(red int64, green int64, blue int64) string
- type AreaPoint
- type Captcha
- func (cc *Captcha) EncodeB64string(img image.Image) string
- func (cc *Captcha) Generate() (map[int]CharDot, string, string, string, error)
- func (cc *Captcha) GenerateWithSize(imageSize *Size, thumbnailSize *Size) (map[int]CharDot, string, string, string, error)
- func (cc *Captcha) SetBackground(images []string)
- func (cc *Captcha) SetFont(fonts []string)
- func (cc *Captcha) SetImageFontAlpha(val float64)
- func (cc *Captcha) SetImageFontDistort(val int)
- func (cc *Captcha) SetImageSize(size *Size)
- func (cc *Captcha) SetRangChars(chars []string) error
- func (cc *Captcha) SetTextRangAnglePos(pos []*RangeVal)
- func (cc *Captcha) SetTextRangFontColors(colors []string)
- func (cc *Captcha) SetTextRangLen(val *RangeVal)
- func (cc *Captcha) SetThumbBackground(images []string)
- func (cc *Captcha) SetThumbBgCirclesNum(val int)
- func (cc *Captcha) SetThumbBgColors(colors []string)
- func (cc *Captcha) SetThumbBgDistort(val int)
- func (cc *Captcha) SetThumbBgSlimLineNum(val int)
- func (cc *Captcha) SetThumbSize(size *Size)
- type CharDot
- type Config
- type Draw
- func (cd *Draw) CreateCanvas(params *DrawCanvas, isAlpha bool) *image.NRGBA
- func (cd *Draw) CreateCanvasWithPalette(params *DrawCanvas, colorArr []color.RGBA) *Palette
- func (cd *Draw) Draw(params *DrawCanvas) (image.Image, error)
- func (cd *Draw) DrawTextImg(dot *DrawDot, params *DrawCanvas) (*Palette, *AreaPoint, error)
- func (cd *Draw) DrawWithPalette(params *DrawCanvas, colorA []color.Color, colorB []color.Color) (image.Image, error)
- type DrawCanvas
- type DrawDot
- type Palette
- type Point
- type RangeVal
- type Size
Constants ¶
View Source
const ( // 无扭曲 ThumbBackgroundDistortNone = iota // 扭曲程度 1-5级别 ThumbBackgroundDistortLevel1 ThumbBackgroundDistortLevel2 ThumbBackgroundDistortLevel3 ThumbBackgroundDistortLevel4 ThumbBackgroundDistortLevel5 )
*
- @Description: 扭曲程度
Variables ¶
This section is empty.
Functions ¶
func GetCaptchaDefaultChars ¶
func GetCaptchaDefaultChars() []string
*
- @Description: 获取字符
- @return map[int]string
func InArrayWithStr ¶
*
- @Description: InArrayS 如果 s 在 items 中,返回 true;否则,返回 false。
- @param items
- @param s
- @return bool
Types ¶
type Captcha ¶
type Captcha struct { // 字符集合,用于随机字符串 Chars []string // 难度码配置 Config *Config // 验证画图 CaptchaDraw *Draw }
*
- @Description: 点选验证码
func (*Captcha) Generate ¶
*
- @Description: 根据设置的尺寸生成验证码图片
- @return CaptchaCharDot 位置信息
- @return string 主图Base64
- @return string 缩略图Base64
- @return error
func (*Captcha) GenerateWithSize ¶
func (cc *Captcha) GenerateWithSize(imageSize *Size, thumbnailSize *Size) (map[int]CharDot, string, string, string, error)
*
- @Description: 生成验证码图片
- @param imageSize 主图尺寸
- @param thumbnailSize 缩略图尺寸
- @return CaptchaCharDot 位置信息
- @return string 主图Base64
- @return string 缩略图Base64
- @return error
func (*Captcha) SetRangChars ¶
*
- @Description: 设置随机字符串,每个单词不能超出2个字符,超出会影响位置的验证
- @receiver cc
- @param chars
- @return error
type CharDot ¶
type CharDot struct { // x,y位置 Dx int Dy int // 字体大小 Size int // 字体宽 Width int // 字体高 Height int // 字符文本 Text string // 字体角度 Angle int // 颜色 Color string }
*
- @Description: 图片点数据
type Config ¶
type Config struct { // 随机字符串长度范围 RangTextLen *RangeVal // 随机验证字符串长度范围, 注意:RangCheckTextLen < RangTextLen RangCheckTextLen *RangeVal // 随机文本角度范围集合 RangTexAnglePos []*RangeVal // 随机文本尺寸范围集合 RangFontSize *RangeVal // 随机缩略文本尺寸范围集合 RangCheckFontSize *RangeVal // 随机文本颜色 格式:"#541245" RangFontColors []string // 随机字体 格式:字体绝对路径字符串, /home/..../xxx.ttf RangFont []string // 屏幕每英寸的分辨率 FontDPI int // 随机验证码背景图 格式:图片绝对路径字符串, /home/..../xxx.png RangBackground []string // 验证码尺寸, 注意:高度 > RangFontSize.max , 长度 > RangFontSize.max * RangFontSize.max ImageSize *Size // 验证码文本扭曲程度 ImageFontDistort int // 验证码文本透明度 0-1 ImageFontAlpha float64 // 缩略图尺寸, 注意:高度 > RangCheckFontSize.max , 长度 > RangCheckFontSize.max * RangFontSize.max ThumbnailSize *Size // 随机缩略背景图 格式:图片绝对路径字符串, /home/..../xxx.png RangThumbBackground []string // 缩略图背景随机色 格式:"#541245" RangThumbBgColors []string // 缩略图扭曲程度,值为 ThumbBackgroundDistort..., ThumbBgDistort int // 缩略图小圆点数量 ThumbBgCirclesNum int // 缩略图线条数量 ThumbBgSlimLineNum int }
* * @Description: 验证码配置
func GetCaptchaDefaultConfig ¶
func GetCaptchaDefaultConfig() *Config
*
- @Description: 获取默认配置
- @return CaptchaConfig
type Draw ¶
type Draw struct{}
*
- @Description: 验证码画图
func (*Draw) CreateCanvas ¶
func (cd *Draw) CreateCanvas(params *DrawCanvas, isAlpha bool) *image.NRGBA
*
- @Description: 创建 NRGBA 画布
- @receiver cd
- @param params
- @param isAlpha
- @return *image.NRGBA
func (*Draw) CreateCanvasWithPalette ¶
func (cd *Draw) CreateCanvasWithPalette(params *DrawCanvas, colorArr []color.RGBA) *Palette
*
- @Description: 创建 Palette 带调包板画布
- @receiver cd
- @param params
- @param colorArr
- @return *Palette
func (*Draw) Draw ¶
func (cd *Draw) Draw(params *DrawCanvas) (image.Image, error)
*
- @Description: 画图
- @receiver cd
- @param params
- @return image.Image
- @return error
func (*Draw) DrawTextImg ¶
*
- @Description: 根据
- @receiver cd
- @param dot
- @param params
- @return *Palette
- @return *AreaPoint
- @return error
type DrawCanvas ¶
type DrawCanvas struct { // 长、高 Width int Height int // 背景图片 Background string // 缩略图扭曲程度,值为 ThumbBackgroundDistort..., BackgroundDistort int // 缩略图小圆点数量 BackgroundCirclesNum int // 缩略图线条数量 BackgroundSlimLineNum int // 文本透明度 TextAlpha float64 CaptchaDrawDot []*DrawDot }
*
- @Description: 验证码画图
type Palette ¶
*
- @Description: 调色板
Source Files ¶
Click to show internal directories.
Click to hide internal directories.