Documentation
¶
Index ¶
- Constants
- Variables
- func ColorToRGB(colorVal int) color.RGBA
- func GenerateCaptcha(width, height int, textLength int, difficulty CaptchaDifficulty) (text string, imgBytes []byte, err error)
- func RandColor() color.RGBA
- func RandDeepColor() color.RGBA
- func RandLightColor() color.RGBA
- func RandText(num int) string
- func Random(min int64, max int64) float64
- func SetFontPath(fontDirPath string) error
- func SetFonts(fonts ...string) error
- type BlurDrawer
- type CaptchaDifficulty
- type CaptchaImage
- func (captcha *CaptchaImage) DrawBlur(drawer BlurDrawer, kernelSize int, sigma float64) *CaptchaImage
- func (captcha *CaptchaImage) DrawBorder(borderColor color.RGBA) *CaptchaImage
- func (captcha *CaptchaImage) DrawLine(drawer LineDrawer, lineColor color.Color) *CaptchaImage
- func (captcha *CaptchaImage) DrawNoise(complex NoiseDensity, noiseDrawer NoiseDrawer) *CaptchaImage
- func (captcha *CaptchaImage) DrawText(textDrawer TextDrawer, text string) *CaptchaImage
- func (captcha *CaptchaImage) Encode(w io.Writer, imageFormat ImageFormat) error
- type FontFamily
- type ImageFormat
- type LineDrawer
- type NoiseDensity
- type NoiseDrawer
- type TextDrawer
Constants ¶
const ( // DefaultDPI 默认的dpi DefaultDPI = 72.0 // DefaultBlurKernelSize 默认模糊卷积核大小 DefaultBlurKernelSize = 2 // DefaultBlurSigma 默认模糊sigma值 DefaultBlurSigma = 0.65 // DefaultAmplitude 默认图片扭曲的振幅 DefaultAmplitude = 20 //DefaultFrequency 默认图片扭曲的波频率 DefaultFrequency = 0.05 )
Variables ¶
var ( ErrNilCanvas = errors.New("canvas is nil") ErrNilText = errors.New("text is nil") )
var DefaultFontFamily = NewFontFamily()
var ErrNoFontsInFamily = os.ErrNotExist
var TextCharacters = []rune("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz0123456789")
Functions ¶
func ColorToRGB ¶
ColorToRGB 颜色代码转换为RGB input int output int red, green, blue.
func GenerateCaptcha ¶
func GenerateCaptcha(width, height int, textLength int, difficulty CaptchaDifficulty) (text string, imgBytes []byte, err error)
GenerateCaptcha 生成验证码图片和对应的文本
func SetFontPath ¶
SetFontPath sets the default font family from a directory
Types ¶
type BlurDrawer ¶
func NewGaussianBlur ¶
func NewGaussianBlur() BlurDrawer
type CaptchaDifficulty ¶
type CaptchaDifficulty int
CaptchaDifficulty 验证码难度级别
const ( // CaptchaVeryEasy 非常简单难度 - 清晰文字,无噪点,无扭曲 CaptchaVeryEasy CaptchaDifficulty = iota // CaptchaEasy 简单难度 - 轻微扭曲,少量噪点 CaptchaEasy // CaptchaMedium 中等难度 - 原来的简单模式 CaptchaMedium // CaptchaHard 困难难度 - 原来的困难模式 CaptchaHard )
type CaptchaImage ¶
func (*CaptchaImage) DrawBlur ¶
func (captcha *CaptchaImage) DrawBlur(drawer BlurDrawer, kernelSize int, sigma float64) *CaptchaImage
DrawBlur 对图片进行模糊处理
func (*CaptchaImage) DrawBorder ¶
func (captcha *CaptchaImage) DrawBorder(borderColor color.RGBA) *CaptchaImage
DrawBorder 画边框.
func (*CaptchaImage) DrawLine ¶
func (captcha *CaptchaImage) DrawLine(drawer LineDrawer, lineColor color.Color) *CaptchaImage
DrawLine 画直线.
func (*CaptchaImage) DrawNoise ¶
func (captcha *CaptchaImage) DrawNoise(complex NoiseDensity, noiseDrawer NoiseDrawer) *CaptchaImage
DrawNoise 画噪点.
func (*CaptchaImage) DrawText ¶
func (captcha *CaptchaImage) DrawText(textDrawer TextDrawer, text string) *CaptchaImage
DrawText 写字.
func (*CaptchaImage) Encode ¶
func (captcha *CaptchaImage) Encode(w io.Writer, imageFormat ImageFormat) error
Encode 编码图片
type FontFamily ¶
type FontFamily struct {
// contains filtered or unexported fields
}
FontFamily is a font family that creates a new font family
func NewFontFamily ¶
func NewFontFamily() *FontFamily
NewFontFamily creates a new font family with the embedded fonts
func (*FontFamily) AddFont ¶
func (f *FontFamily) AddFont(fontFile string) error
AddFont adds a font to the family and returns an error if it fails
func (*FontFamily) AddFontPath ¶
func (f *FontFamily) AddFontPath(dirPath string) error
AddFontPath adds all .ttf files from the given directory to the font family and returns an error if any
type ImageFormat ¶
type ImageFormat int
ImageFormat 图片格式
const ( ImageFormatPng ImageFormat = iota ImageFormatJpeg ImageFormatGif )
type LineDrawer ¶
type LineDrawer interface {
DrawLine(canvas draw.Image, x image.Point, y image.Point, color color.Color) error
}
LineDrawer 实现划线的接口
func NewBeeline ¶
func NewBeeline() LineDrawer
type NoiseDensity ¶
type NoiseDensity int
NoiseDensity is the complexity of captcha
const ( NoiseDensityLower NoiseDensity = iota NoiseDensityMedium NoiseDensityHigh )
type NoiseDrawer ¶
type NoiseDrawer interface {
// DrawNoise draws noise on the image
DrawNoise(img draw.Image, density NoiseDensity) error
}
NoiseDrawer is a type that can make noise on an image
func NewPointNoiseDrawer ¶
func NewPointNoiseDrawer() NoiseDrawer
NewPointNoiseDrawer returns a NoiseDrawer that draws noise points
func NewTextNoiseDrawer ¶
func NewTextNoiseDrawer(dpi float64) NoiseDrawer
type TextDrawer ¶
TextDrawer is a text drawer interface.
func NewTextDrawer ¶
func NewTextDrawer(dpi float64) TextDrawer
NewTextDrawer returns a new text drawer.
func NewTwistTextDrawer ¶
func NewTwistTextDrawer(dpi float64, amplitude float64, frequency float64) TextDrawer
NewTwistTextDrawer returns a new text drawer with twist effect.
