Documentation ¶
Index ¶
- Constants
- func Check(recorded map[int]CharDot, postDots string) bool
- func CheckPointDist(sx, sy, dx, dy, width, height int64) bool
- func CheckPointDistWithPadding(sx, sy, dx, dy, width, height, padding int64) bool
- func Child(path string) ([]string, error)
- func ClearAssetCacheWithPaths(paths []string) bool
- func EncodeB64stringWithJpeg(img image.Image, quality int) (string, error)
- func EncodeB64stringWithPng(img image.Image) (string, error)
- func GenUniqueId() string
- 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) int
- func RgbToHex(red int64, green int64, blue int64) string
- func Sup(i int64, n int) string
- type AreaPoint
- type Captcha
- func (cc *Captcha) ClearAssetCacheWithPaths(paths []string) bool
- func (cc *Captcha) EncodeB64stringWithJpeg(img image.Image) (string, error)
- func (cc *Captcha) EncodeB64stringWithPng(img image.Image) (string, error)
- 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, args ...bool)
- func (cc *Captcha) SetFont(fonts []string, args ...bool)
- func (cc *Captcha) SetFontDPI(val int)
- func (cc *Captcha) SetFontHinting(val font.Hinting)
- func (cc *Captcha) SetImageFontAlpha(val float64)
- func (cc *Captcha) SetImageFontDistort(val int)
- func (cc *Captcha) SetImageQuality(val int)
- func (cc *Captcha) SetImageSize(size Size)
- func (cc *Captcha) SetRangChars(chars []string) error
- func (cc *Captcha) SetRangCheckFontSize(val RangeVal)
- func (cc *Captcha) SetRangCheckTextLen(val RangeVal)
- func (cc *Captcha) SetRangFontSize(val RangeVal)
- func (cc *Captcha) SetTextRangAnglePos(pos []RangeVal)
- func (cc *Captcha) SetTextRangFontColors(colors []string)
- func (cc *Captcha) SetTextRangLen(val RangeVal)
- func (cc *Captcha) SetTextShadow(val bool)
- func (cc *Captcha) SetTextShadowColor(val string)
- func (cc *Captcha) SetTextShadowPoint(val Point)
- func (cc *Captcha) SetThumbBackground(images []string, args ...bool)
- 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) SetThumbFontDistort(val int)
- func (cc *Captcha) SetThumbSize(size Size)
- func (cc *Captcha) SetThumbTextRangFontColors(colors []string)
- type CharDot
- type Config
- type Draw
- func (cd *Draw) CreateCanvas(params DrawCanvas, isAlpha bool) (img *image.NRGBA)
- func (cd *Draw) CreateCanvasWithPalette(params DrawCanvas, colorArr []color.RGBA) *Palette
- func (cd *Draw) Draw(params DrawCanvas) (image.Image, error)
- func (cd *Draw) DrawStrImg(dot DrawDot, colorArr []color.RGBA, fc color.Color) (*Palette, 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 ¶
const ( // 无扭曲 DistortNone = iota // 扭曲程度 1-5级别 DistortLevel1 DistortLevel2 DistortLevel3 DistortLevel4 DistortLevel5 )
*
- @Description: 扭曲程度
const ( // 无压缩质量,原图 QualityCompressNone = iota // 质量压缩程度 1-5 级别,压缩级别越低图像越清晰 QualityCompressLevel1 = 100 QualityCompressLevel2 = 80 QualityCompressLevel3 = 60 QualityCompressLevel4 = 40 QualityCompressLevel5 = 20 )
*
- @Description: 质量压缩程度
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check is a function *
- @Description: 监测
- @param recorded 记录的数据
- @param postDots 前端用户操作提交的数据
- @return bool
func CheckPointDist ¶
CheckPointDist is a function *
- @Description: 计算点的位置在区域是否命中
- @param sx 用户点击的x轴
- @param sy 用户点击的y轴
- @param dx 校验文本的x轴
- @param dy 校验文本的y轴
- @param width 校验文本的宽度
- @param height 校验文本的高度
- @return bool
func CheckPointDistWithPadding ¶
CheckPointDistWithPadding is a function *
- @Description: 计算点的位置在扩张区域(原区域+外边距)是否命中
- @param sx 用户点击的x轴
- @param sy 用户点击的y轴
- @param dx 校验文本的x轴
- @param dy 校验文本的y轴
- @param width 校验文本的宽度
- @param height 校验文本的高度
- @param padding 在原有的区域上添加额外边距进行扩张计算区域,不推荐设置过大的padding
- @return bool
func ClearAssetCacheWithPaths ¶
============================================= Call API ============================================= ClearAssetCacheWithPaths is a function *
- @Description: 根据路径清除资源缓存
- @param paths
- @return bool
func EncodeB64stringWithJpeg ¶
EncodeB64string is a function *
- @Description: base64编码
- @param img 图片
- @param quality 清晰度
- @return string
func EncodeB64stringWithPng ¶
EncodeB64string is a function *
- @Description: base64编码
- @param img
- @return string
func GenUniqueId ¶
func GenUniqueId() string
func GetCaptchaDefaultChars ¶
func GetCaptchaDefaultChars() *[]string
GetCaptchaDefaultChars is a type *
- @Description: 获取字符
- @return map[int]string
func HexToRgb ¶
HexToRgb is a function *
- @Description: 十六进制转RBG颜色
- @param hex
- @return int64
- @return int64
- @return int64
func InArrayWithStr ¶
InArrayWithStr is a function *
- @Description: InArrayS 如果 s 在 items 中,返回 true;否则,返回 false。
- @param items
- @param s
- @return bool
func LenChineseChar ¶
LenChineseChar is a function *
- @Description: 计算中文及字母长度,例如:“你好hello” = 7
- @param str
- @return int
func ParseHexColor ¶
ParseHexColor is a function *
- @Description: 把十六进制颜色转 color.RGBA
- @param v
- @return out
- @return err
func PathExists ¶
PathExists is a function *
- @Description: 检测文件是否存在
- @param path
- @return bool
- @return error
func RandFloat ¶
RandFloat is a function *
- @Description: 随机浮点数
- @param min
- @param max
- @return float64
func RandInt ¶
RandInt is a function *
- @Description: 生成区间[-m, n]的安全随机数
- @param min
- @param max
- @return int
Types ¶
type AreaPoint ¶
type AreaPoint struct {
MinX, MaxX, MinY, MaxY int
}
AreaPoint is a type *
- @Description: 区域点信息
type Captcha ¶
type Captcha struct {
// contains filtered or unexported fields
}
Captcha is a type *
- @Description: 点选验证码
func GetCaptcha ¶
func GetCaptcha() *Captcha
GetCaptcha is a function *
- @Description: 获取点选验证码,是安全的
- @return *Captcha
func NewCaptcha ¶
func NewCaptcha() *Captcha
NewCaptcha is a function *
- @Description: 创建点选验证码
- @return *Captcha
func (*Captcha) ClearAssetCacheWithPaths ¶
============================================= Captcha Call API ============================================= *
- @Description: 根据路径清除资源缓存
- @param paths
- @return bool
func (*Captcha) EncodeB64stringWithJpeg ¶
EncodeB64string is a function *
- @Description: base64编码
- @receiver cc
- @param img
- @return string
func (*Captcha) EncodeB64stringWithPng ¶
EncodeB64string is a function *
- @Description: base64编码
- @receiver cc
- @param img
- @return string
func (*Captcha) Generate ¶
Generate is a function *
- @Description: 根据设置的尺寸生成验证码图片
- @return CaptchaCharDot 位置信息
- @return string 主图Base64
- @return string 验证码KEY
- @return string 缩略图Base64
- @return error
func (*Captcha) GenerateWithSize ¶
func (cc *Captcha) GenerateWithSize(imageSize Size, thumbnailSize Size) (map[int]CharDot, string, string, string, error)
GenerateWithSize is a function *
- @Description: 生成验证码图片
- @param imageSize 主图尺寸
- @param thumbnailSize 缩略图尺寸
- @return CaptchaCharDot 位置信息
- @return string 主图Base64
- @return string 验证码KEY
- @return string 缩略图Base64
- @return error
func (*Captcha) SetBackground ¶
SetBackground is a function *
- @Description: 设置随机背景图片
- @receiver cc
- @param images
- @param args true|false 是否强制刷新缓存
func (*Captcha) SetFont ¶
SetFont is a function *
- @Description: 设置随机字体
- @receiver cc
- @param fonts
- @param args true|false 是否强制刷新缓存
func (*Captcha) SetFontDPI ¶
SetFontDPI is a function *
- @Description: 设置分辨率,72为标准
- @receiver cc
- @param val
func (*Captcha) SetFontHinting ¶
SetFontDPI is a function *
- @Description: 设置分辨率,72为标准
- @receiver cc
- @param val
func (*Captcha) SetImageFontAlpha ¶
SetImageFontAlpha is a function *
- @Description: 设置验证码文本透明度
- @receiver cc
- @param val
func (*Captcha) SetImageFontDistort ¶
SetImageFontDistort is a function *
- @Description: 设置验证码文本扭曲程度
- @receiver cc
- @param val
func (*Captcha) SetImageQuality ¶
SetImageQuality is a function *
- @Description: 设置验证码清晰度
- @receiver cc
- @param val
func (*Captcha) SetImageSize ¶
SetImageSize is a function *
- @Description: 设置验证码尺寸
- @receiver cc
- @param size
func (*Captcha) SetRangChars ¶
SetRangChars is a function *
- @Description: 设置随机字符串,每个单词不能超出2个字符,超出会影响位置的验证
- @receiver cc
- @param chars
- @return error
func (*Captcha) SetRangCheckFontSize ¶
SetRangCheckFontSize is a function *
- @Description: 设置随机验证文本大小
- @receiver cc
- @param val
func (*Captcha) SetRangCheckTextLen ¶
SetRangCheckTextLen is a function *
- @Description: 设置随机验证文本长度
- @receiver cc
- @param val
func (*Captcha) SetRangFontSize ¶
SetRangFontSize is a function *
- @Description: 设置随机字体大小
- @receiver cc
- @param val
func (*Captcha) SetTextRangAnglePos ¶
SetTextRangAnglePos is a function *
- @Description: 设置文本角度位置
- @receiver cc
- @param pos
func (*Captcha) SetTextRangFontColors ¶
SetTextRangFontColors is a function *
- @Description: 设置文本随机颜色
- @receiver cc
- @param colors
func (*Captcha) SetTextRangLen ¶
SetTextRangLen is a function *
- @Description: 设置字符随机长度范围
- @receiver cc
- @param val
func (*Captcha) SetTextShadow ¶
SetTextShadow is a function *
- @Description: 设置验证码文本阴影显示
- @receiver cc
- @param val
func (*Captcha) SetTextShadowColor ¶
SetTextShadowColor is a function *
- @Description: 设置验证码文本阴影颜色
- @receiver cc
- @param val
func (*Captcha) SetTextShadowPoint ¶
SetTextShadowPoint is a function *
- @Description: 设置验证码文本阴影位置
- @receiver cc
- @param val
func (*Captcha) SetThumbBackground ¶
SetThumbBackground is a function *
- @Description: 设置随机背景图片
- @receiver cc
- @param images
- @param args true|false 是否强制刷新缓存
func (*Captcha) SetThumbBgCirclesNum ¶
SetThumbBgCirclesNum is a function *
- @Description: 设置缩略图小圆点数量
- @receiver cc
- @param val
func (*Captcha) SetThumbBgColors ¶
SetThumbBgColors is a function *
- @Description: 设置缩略图随机背景颜色
- @receiver cc
- @param colors
func (*Captcha) SetThumbBgDistort ¶
SetThumbBgDistort is a function *
- @Description: 设置缩略图扭曲程度
- @receiver cc
- @param val
func (*Captcha) SetThumbBgSlimLineNum ¶
SetThumbBgSlimLineNum is a function *
- @Description: 缩略图线条数量
- @receiver cc
- @param val
func (*Captcha) SetThumbFontDistort ¶
SetThumbFontDistort is a function *
- @Description: 设置缩略图字体扭曲程度
- @receiver cc
- @param val
func (*Captcha) SetThumbSize ¶
SetThumbSize is a function *
- @Description: 设置缩略图尺寸
- @receiver cc
- @param size
func (*Captcha) SetThumbTextRangFontColors ¶
SetThumbTextRangFontColors is a function *
- @Description: 设置缩略图文本随机颜色
- @receiver cc
- @param colors
type CharDot ¶
type CharDot struct { // 顺序索引 Index int // x,y位置 Dx int Dy int // 字体大小 Size int // 字体宽 Width int // 字体高 Height int // 字符文本 Text string // 字体角度 Angle int // 颜色 Color string // 颜色2 Color2 string }
CharDot is a type *
- @Description: 图片点数据
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is a type * * @Description: 验证码配置
func GetCaptchaDefaultConfig ¶
func GetCaptchaDefaultConfig() *Config
GetCaptchaDefaultConfig is a type *
- @Description: 获取默认配置
- @return CaptchaConfig
type Draw ¶
type Draw struct{}
Draw is a type *
- @Description: 验证码画图
func (*Draw) CreateCanvas ¶
func (cd *Draw) CreateCanvas(params DrawCanvas, isAlpha bool) (img *image.NRGBA)
CreateCanvas is a function *
- @Description: 创建 NRGBA 画布
- @receiver cd
- @param params
- @param isAlpha
- @return *image.NRGBA
func (*Draw) CreateCanvasWithPalette ¶
func (cd *Draw) CreateCanvasWithPalette(params DrawCanvas, colorArr []color.RGBA) *Palette
CreateCanvasWithPalette is a function *
- @Description: 创建 Palette 带调色板的画布
- @receiver cd
- @param params
- @param colorArr
- @return *Palette
func (*Draw) Draw ¶
func (cd *Draw) Draw(params DrawCanvas) (image.Image, error)
Draw is a function *
- @Description: 画图
- @receiver cd
- @param params
- @return image.Image
- @return error
func (*Draw) DrawStrImg ¶
DrawTextImg is a function *
- @Description: 绘制文本的图片
- @receiver cd
- @param dot
- @param params
- @return *Palette
- @return *AreaPoint
- @return error
func (*Draw) DrawTextImg ¶
DrawTextImg is a function *
- @Description: 绘制文本的图片
- @receiver cd
- @param dot
- @param params
- @return *Palette
- @return *AreaPoint
- @return error
type DrawCanvas ¶
type DrawCanvas struct { // 长、高 Width int Height int // 背景图片 Background string // 缩略图扭曲程度,值为 Distort..., BackgroundDistort int // 缩略图小圆点数量 BackgroundCirclesNum int // 缩略图线条数量 BackgroundSlimLineNum int // 文本透明度 TextAlpha float64 // FontHinting FontHinting font.Hinting // 点 CaptchaDrawDot []DrawDot // 文本阴影偏移位置 ShowTextShadow bool // 文本阴影颜色 TextShadowColor string // 文本阴影偏移位置 TextShadowPoint Point }
DrawCanvas is a type *
- @Description: 验证码画图
type DrawDot ¶
type DrawDot struct { Dx int Dy int FontDPI int Text string Size int Width int Height int Angle int Color string Color2 string Font string }
DrawDot is a type
type Palette ¶
Palette is a type *
- @Description: 调色板