Documentation ¶
Index ¶
- Constants
- Variables
- func ColorToRGB(colorVal int) color.RGBA
- 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 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("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
Functions ¶
func ColorToRGB ¶
ColorToRGB 颜色代码转换为RGB input int output int red, green, blue.
func SetFontPath ¶ added in v1.0.0
SetFontPath sets the default font family from a directory
Types ¶
type BlurDrawer ¶ added in v1.0.0
func NewGaussianBlur ¶ added in v1.0.0
func NewGaussianBlur() BlurDrawer
type CaptchaImage ¶
func New ¶ added in v0.2.0
func New(width int, height int, bgColor color.RGBA) *CaptchaImage
New 新建一个图片对象
func (*CaptchaImage) DrawBlur ¶ added in v1.0.0
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 ¶ added in v1.0.0
func (captcha *CaptchaImage) Encode(w io.Writer, imageFormat ImageFormat) error
Encode 编码图片
type FontFamily ¶ added in v1.0.0
type FontFamily struct {
// contains filtered or unexported fields
}
FontFamily is a font family that creates a new font family
func NewFontFamily ¶ added in v1.0.0
func NewFontFamily() *FontFamily
NewFontFamily creates a new font family with the given fonts
func (*FontFamily) AddFont ¶ added in v1.0.0
func (f *FontFamily) AddFont(fontFile string) error
AddFont adds a font to the family and returns an error if it fails
func (*FontFamily) AddFontPath ¶ added in v1.0.0
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 ¶ added in v1.0.0
type LineDrawer interface {
DrawLine(canvas draw.Image, x image.Point, y image.Point, color color.Color) error
}
LineDrawer 实现划线的接口
func NewBeeline ¶ added in v1.0.0
func NewBeeline() LineDrawer
type NoiseDensity ¶ added in v1.0.0
type NoiseDensity int
NoiseDensity is the complexity of captcha
const ( NoiseDensityLower NoiseDensity = iota NoiseDensityMedium NoiseDensityHigh )
type NoiseDrawer ¶ added in v1.0.0
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 ¶ added in v1.0.0
func NewPointNoiseDrawer() NoiseDrawer
NewPointNoiseDrawer returns a NoiseDrawer that draws noise points
func NewTextNoiseDrawer ¶ added in v1.0.0
func NewTextNoiseDrawer(dpi float64) NoiseDrawer
type TextDrawer ¶ added in v1.0.0
TextDrawer is a text drawer interface.
func NewTextDrawer ¶ added in v1.0.0
func NewTextDrawer(dpi float64) TextDrawer
NewTextDrawer returns a new text drawer.
func NewTwistTextDrawer ¶ added in v1.0.0
func NewTwistTextDrawer(dpi float64, amplitude float64, frequency float64) TextDrawer
NewTwistTextDrawer returns a new text drawer with twist effect.