captcha

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 无扭曲
	DistortNone = iota
	// 扭曲程度 1-5级别
	DistortLevel1
	DistortLevel2
	DistortLevel3
	DistortLevel4
	DistortLevel5
)

*

  • @Description: 扭曲程度
View Source
const (
	// 无压缩质量,原图
	QualityCompressNone = iota
	// 质量压缩程度 1-5 级别,压缩级别越低图像越清晰
	QualityCompressLevel1 = 100
	QualityCompressLevel2 = 80
	QualityCompressLevel3 = 60
	QualityCompressLevel4 = 40
	QualityCompressLevel5 = 20
)

*

  • @Description: 质量压缩程度

Variables

This section is empty.

Functions

func Check

func Check(recorded map[int]CharDot, postDots string) bool

Check is a function *

  • @Description: 监测
  • @param recorded 记录的数据
  • @param postDots 前端用户操作提交的数据
  • @return bool

func CheckPointDist

func CheckPointDist(sx, sy, dx, dy, width, height int64) bool

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

func CheckPointDistWithPadding(sx, sy, dx, dy, width, height, padding int64) bool

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 Child

func Child(path string) ([]string, error)

Child is a function *

  • @Description: 获取路径
  • @param path
  • @return []string

func ClearAssetCacheWithPaths

func ClearAssetCacheWithPaths(paths []string) bool

============================================= Call API ============================================= ClearAssetCacheWithPaths is a function *

  • @Description: 根据路径清除资源缓存
  • @param paths
  • @return bool

func EncodeB64stringWithJpeg

func EncodeB64stringWithJpeg(img image.Image, quality int) (string, error)

EncodeB64string is a function *

  • @Description: base64编码
  • @param img 图片
  • @param quality 清晰度
  • @return string

func EncodeB64stringWithPng

func EncodeB64stringWithPng(img image.Image) (string, error)

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

func HexToRgb(hex string) (int64, int64, int64)

HexToRgb is a function *

  • @Description: 十六进制转RBG颜色
  • @param hex
  • @return int64
  • @return int64
  • @return int64

func InArrayWithStr

func InArrayWithStr(items []string, s string) bool

InArrayWithStr is a function *

  • @Description: InArrayS 如果 s 在 items 中,返回 true;否则,返回 false。
  • @param items
  • @param s
  • @return bool

func IsChineseChar

func IsChineseChar(str string) bool

IsChineseChar is a function *

  • @Description: 判断是否是中文
  • @param str
  • @return bool

func LenChineseChar

func LenChineseChar(str string) int

LenChineseChar is a function *

  • @Description: 计算中文及字母长度,例如:“你好hello” = 7
  • @param str
  • @return int

func Md5ToString

func Md5ToString(str string) string

Md5ToString is a function *

  • @Description: Md5
  • @param str
  • @return string

func ParseHexColor

func ParseHexColor(s string) (c color.RGBA, err error)

ParseHexColor is a function *

  • @Description: 把十六进制颜色转 color.RGBA
  • @param v
  • @return out
  • @return err

func PathExists

func PathExists(path string) (bool, error)

PathExists is a function *

  • @Description: 检测文件是否存在
  • @param path
  • @return bool
  • @return error

func RandFloat

func RandFloat(min, max int) float64

RandFloat is a function *

  • @Description: 随机浮点数
  • @param min
  • @param max
  • @return float64

func RandInt

func RandInt(min, max int) int

RandInt is a function *

  • @Description: 生成区间[-m, n]的安全随机数
  • @param min
  • @param max
  • @return int

func RgbToHex

func RgbToHex(red int64, green int64, blue int64) string

RgbToHex is a function *

  • @Description: RBG颜色转十六进制颜色
  • @param red
  • @param green
  • @param blue
  • @return CaptchaColorHEX

func Sup

func Sup(i int64, n int) string

Sup is a function *

  • @Description: 对长度不足n的数字前面补0
  • @param int64
  • @param int
  • @return string

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

func (cc *Captcha) ClearAssetCacheWithPaths(paths []string) bool

============================================= Captcha Call API ============================================= *

  • @Description: 根据路径清除资源缓存
  • @param paths
  • @return bool

func (*Captcha) EncodeB64stringWithJpeg

func (cc *Captcha) EncodeB64stringWithJpeg(img image.Image) (string, error)

EncodeB64string is a function *

  • @Description: base64编码
  • @receiver cc
  • @param img
  • @return string

func (*Captcha) EncodeB64stringWithPng

func (cc *Captcha) EncodeB64stringWithPng(img image.Image) (string, error)

EncodeB64string is a function *

  • @Description: base64编码
  • @receiver cc
  • @param img
  • @return string

func (*Captcha) Generate

func (cc *Captcha) Generate() (map[int]CharDot, string, string, string, error)

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

func (cc *Captcha) SetBackground(images []string, args ...bool)

SetBackground is a function *

  • @Description: 设置随机背景图片
  • @receiver cc
  • @param images
  • @param args true|false 是否强制刷新缓存

func (*Captcha) SetFont

func (cc *Captcha) SetFont(fonts []string, args ...bool)

SetFont is a function *

  • @Description: 设置随机字体
  • @receiver cc
  • @param fonts
  • @param args true|false 是否强制刷新缓存

func (*Captcha) SetFontDPI

func (cc *Captcha) SetFontDPI(val int)

SetFontDPI is a function *

  • @Description: 设置分辨率,72为标准
  • @receiver cc
  • @param val

func (*Captcha) SetFontHinting

func (cc *Captcha) SetFontHinting(val font.Hinting)

SetFontDPI is a function *

  • @Description: 设置分辨率,72为标准
  • @receiver cc
  • @param val

func (*Captcha) SetImageFontAlpha

func (cc *Captcha) SetImageFontAlpha(val float64)

SetImageFontAlpha is a function *

  • @Description: 设置验证码文本透明度
  • @receiver cc
  • @param val

func (*Captcha) SetImageFontDistort

func (cc *Captcha) SetImageFontDistort(val int)

SetImageFontDistort is a function *

  • @Description: 设置验证码文本扭曲程度
  • @receiver cc
  • @param val

func (*Captcha) SetImageQuality

func (cc *Captcha) SetImageQuality(val int)

SetImageQuality is a function *

  • @Description: 设置验证码清晰度
  • @receiver cc
  • @param val

func (*Captcha) SetImageSize

func (cc *Captcha) SetImageSize(size Size)

SetImageSize is a function *

  • @Description: 设置验证码尺寸
  • @receiver cc
  • @param size

func (*Captcha) SetRangChars

func (cc *Captcha) SetRangChars(chars []string) error

SetRangChars is a function *

  • @Description: 设置随机字符串,每个单词不能超出2个字符,超出会影响位置的验证
  • @receiver cc
  • @param chars
  • @return error

func (*Captcha) SetRangCheckFontSize

func (cc *Captcha) SetRangCheckFontSize(val RangeVal)

SetRangCheckFontSize is a function *

  • @Description: 设置随机验证文本大小
  • @receiver cc
  • @param val

func (*Captcha) SetRangCheckTextLen

func (cc *Captcha) SetRangCheckTextLen(val RangeVal)

SetRangCheckTextLen is a function *

  • @Description: 设置随机验证文本长度
  • @receiver cc
  • @param val

func (*Captcha) SetRangFontSize

func (cc *Captcha) SetRangFontSize(val RangeVal)

SetRangFontSize is a function *

  • @Description: 设置随机字体大小
  • @receiver cc
  • @param val

func (*Captcha) SetTextRangAnglePos

func (cc *Captcha) SetTextRangAnglePos(pos []RangeVal)

SetTextRangAnglePos is a function *

  • @Description: 设置文本角度位置
  • @receiver cc
  • @param pos

func (*Captcha) SetTextRangFontColors

func (cc *Captcha) SetTextRangFontColors(colors []string)

SetTextRangFontColors is a function *

  • @Description: 设置文本随机颜色
  • @receiver cc
  • @param colors

func (*Captcha) SetTextRangLen

func (cc *Captcha) SetTextRangLen(val RangeVal)

SetTextRangLen is a function *

  • @Description: 设置字符随机长度范围
  • @receiver cc
  • @param val

func (*Captcha) SetTextShadow

func (cc *Captcha) SetTextShadow(val bool)

SetTextShadow is a function *

  • @Description: 设置验证码文本阴影显示
  • @receiver cc
  • @param val

func (*Captcha) SetTextShadowColor

func (cc *Captcha) SetTextShadowColor(val string)

SetTextShadowColor is a function *

  • @Description: 设置验证码文本阴影颜色
  • @receiver cc
  • @param val

func (*Captcha) SetTextShadowPoint

func (cc *Captcha) SetTextShadowPoint(val Point)

SetTextShadowPoint is a function *

  • @Description: 设置验证码文本阴影位置
  • @receiver cc
  • @param val

func (*Captcha) SetThumbBackground

func (cc *Captcha) SetThumbBackground(images []string, args ...bool)

SetThumbBackground is a function *

  • @Description: 设置随机背景图片
  • @receiver cc
  • @param images
  • @param args true|false 是否强制刷新缓存

func (*Captcha) SetThumbBgCirclesNum

func (cc *Captcha) SetThumbBgCirclesNum(val int)

SetThumbBgCirclesNum is a function *

  • @Description: 设置缩略图小圆点数量
  • @receiver cc
  • @param val

func (*Captcha) SetThumbBgColors

func (cc *Captcha) SetThumbBgColors(colors []string)

SetThumbBgColors is a function *

  • @Description: 设置缩略图随机背景颜色
  • @receiver cc
  • @param colors

func (*Captcha) SetThumbBgDistort

func (cc *Captcha) SetThumbBgDistort(val int)

SetThumbBgDistort is a function *

  • @Description: 设置缩略图扭曲程度
  • @receiver cc
  • @param val

func (*Captcha) SetThumbBgSlimLineNum

func (cc *Captcha) SetThumbBgSlimLineNum(val int)

SetThumbBgSlimLineNum is a function *

  • @Description: 缩略图线条数量
  • @receiver cc
  • @param val

func (*Captcha) SetThumbFontDistort

func (cc *Captcha) SetThumbFontDistort(val int)

SetThumbFontDistort is a function *

  • @Description: 设置缩略图字体扭曲程度
  • @receiver cc
  • @param val

func (*Captcha) SetThumbSize

func (cc *Captcha) SetThumbSize(size Size)

SetThumbSize is a function *

  • @Description: 设置缩略图尺寸
  • @receiver cc
  • @param size

func (*Captcha) SetThumbTextRangFontColors

func (cc *Captcha) SetThumbTextRangFontColors(colors []string)

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

func (cd *Draw) DrawStrImg(dot DrawDot, colorArr []color.RGBA, fc color.Color) (*Palette, error)

DrawTextImg is a function *

  • @Description: 绘制文本的图片
  • @receiver cd
  • @param dot
  • @param params
  • @return *Palette
  • @return *AreaPoint
  • @return error

func (*Draw) DrawTextImg

func (cd *Draw) DrawTextImg(dot DrawDot, params DrawCanvas) (*Palette, *AreaPoint, error)

DrawTextImg is a function *

  • @Description: 绘制文本的图片
  • @receiver cd
  • @param dot
  • @param params
  • @return *Palette
  • @return *AreaPoint
  • @return error

func (*Draw) DrawWithPalette

func (cd *Draw) DrawWithPalette(params DrawCanvas, colorA []color.Color, colorB []color.Color) (image.Image, error)

DrawWithPalette is a function *

  • @Description: 使用调色板的画布绘图
  • @receiver cd
  • @param params
  • @param colorA
  • @param colorB
  • @return image.Image
  • @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

type Palette struct {
	*image.Paletted
}

Palette is a type *

  • @Description: 调色板

func NewPalette

func NewPalette(r image.Rectangle, p color.Palette) *Palette

NewPalette is a function *

  • @Description: 创建调色板
  • @param r
  • @param p
  • @return *Palette

func (*Palette) Rotate

func (p *Palette) Rotate(angle int)

Rotate is a function *

  • @Description: 旋转任意角度
  • @receiver p
  • @param angle

type Point

type Point struct {
	X, Y int
}

Point is a type *

  • @Description: 点

type RangeVal

type RangeVal struct {
	Min, Max int
}

RangeVal is a type *

  • @Description: 范围值
  • @Example: {min: 0, max: 45} 从0-45中取任意值

type Size

type Size struct {
	Width, Height int
}

Size is a type *

  • @Description: 尺寸
  • @Example: {width: 0, height: 45} 从0-45中取任意值

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL