click

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyShapesErr          = errors.New("no shapes provided")
	EmptyCharacterErr       = errors.New("no character provided")
	CharRangeLenErr         = errors.New("character length must be greater than rangeLen.Max")
	ShapesRangeLenErr       = errors.New("total number of shapes must be greater than rangeLen.Max")
	ShapesTypeErr           = errors.New("shape must be an image type")
	EmptyBackgroundImageErr = errors.New("no background image")
	ModeSupportErr          = errors.New("mode is not supported")
)
View Source
var (
	ColorLenErr       = errors.New("the color length must be less than or equal to 255")
	RangeVerifyLenErr = errors.New("the max value of 'rangeVerifyLen' must be less than or equal to the min value of 'rangeLen'")
)
View Source
var (
	ChineseCharLenErr = errors.New("the chinese char length must be equal to 1")
	CharLenErr        = errors.New("the char length must be less than or equal to 2")
)

Functions

func CheckPoint deprecated

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

Deprecated: As of 2.1.0, it will be removed, please use click.Validate

func Validate

func Validate(sx, sy, dx, dy, width, height, padding int) bool

Validate checks if a click point is within the specified area params:

  • sx, sy: Coordinates of the click point
  • dx, dy: Top-left coordinates of the target area
  • width, height: Width and height of the target area
  • padding: Padding of the area

return: Whether the point is within the area

Types

type Builder

type Builder interface {
	SetOptions(opts ...Option)
	SetResources(resources ...Resource)
	Clear()
	Make() Captcha
	MakeShape() Captcha
	// Deprecated: As of 2.1.0, it will be removed, please use [MakeShape].
	MakeWithShape() Captcha
}

Builder defines an interface for building captcha

func NewBuilder

func NewBuilder(opts ...Option) Builder

NewBuilder creates a new Builder instance opts: Optional initial options return: Builder interface instance

type CaptData

type CaptData struct {
	// contains filtered or unexported fields
}

CaptData is the concrete implementation of the CaptchaData interface

func (CaptData) GetData

func (c CaptData) GetData() map[int]*Dot

GetData gets the dot data of the captcha return: Map of dot data

func (CaptData) GetMasterImage

func (c CaptData) GetMasterImage() imagedata.JPEGImageData

GetMasterImage gets the main captcha image return: Main image in JPEG format

func (CaptData) GetThumbImage

func (c CaptData) GetThumbImage() imagedata.PNGImageData

GetThumbImage gets the thumbnail image return: Thumbnail image in PNG format

type Captcha

type Captcha interface {
	GetOptions() *Options
	Generate(group string) (CaptchaData, error)
	// contains filtered or unexported methods
}

Captcha defines the interface for captcha

type CaptchaData

type CaptchaData interface {
	GetData() map[int]*Dot
	GetMasterImage() imagedata.JPEGImageData
	GetThumbImage() imagedata.PNGImageData
}

CaptchaData defines the interface for captcha data

type Dot

type Dot struct {
	Index  int    `json:"index"`
	X      int    `json:"x"`
	Y      int    `json:"y"`
	Size   int    `json:"size"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
	Text   string `json:"text"`
	Shape  string `json:"shape"`
	Angle  int    `json:"angle"`
	Color  string `json:"color"`
	Color2 string `json:"color2"`
}

Dot represents a single point (character or shape) in the captcha

type DrawDot

type DrawDot struct {
	Dot              *Dot
	X                int
	Y                int
	FontDPI          int
	Text             string
	Image            image.Image
	UseOriginalColor bool
	Size             int
	Width            int
	Height           int
	Angle            int
	Color            string
	Color2           string
	Font             *truetype.Font
	DrawType         DrawType
}

DrawDot represents the dot data used for drawing

type DrawImage

type DrawImage interface {
	DrawWithNRGBA(params *DrawImageParams) (image.Image, error)
	DrawWithPalette(params *DrawImageParams, textColors []color.Color, bgColors []color.Color) (image.Image, error)
	DrawWithNRGBA2(params *DrawImageParams, textColors []color.Color, bgColors []color.Color) (image.Image, error)
}

DrawImage defines the interface for drawing images

func NewDrawImage

func NewDrawImage() DrawImage

NewDrawImage creates a new DrawImage instance return: DrawImage interface instance

type DrawImageParams

type DrawImageParams struct {
	Width                 int
	Height                int
	Background            image.Image
	BackgroundDistort     int
	BackgroundCirclesNum  int
	BackgroundSlimLineNum int
	Alpha                 float32
	FontHinting           font.Hinting
	CaptchaDrawDot        []*DrawDot
	ShowShadow            bool
	ShadowColor           string
	ShadowPoint           *option.Point
	ThumbDisturbAlpha     float32
}

DrawImageParams defines the parameters for drawing images

type DrawType

type DrawType int
const (
	DrawTypeString DrawType = iota
	DrawTypeImage
)

type Mode

type Mode int

Mode defines the mode of the captcha

const (
	ModeText  Mode = iota // Text mode
	ModeShape             // Shape mode
)

type Option

type Option func(*Options)

func WithDisabledRangeVerifyLen

func WithDisabledRangeVerifyLen(disabled bool) Option

WithDisabledRangeVerifyLen .

func WithDisplayShadow

func WithDisplayShadow(val bool) Option

WithDisplayShadow .

func WithFontHinting

func WithFontHinting(val font.Hinting) Option

WithFontHinting .

func WithImageAlpha

func WithImageAlpha(val float32) Option

WithImageAlpha .

func WithImageSize

func WithImageSize(val option.Size) Option

WithImageSize .

func WithIsThumbNonDeformAbility

func WithIsThumbNonDeformAbility(val bool) Option

WithIsThumbNonDeformAbility .

func WithRangeAnglePos

func WithRangeAnglePos(vals []option.RangeVal) Option

WithRangeAnglePos .

func WithRangeColors

func WithRangeColors(colors []string) Option

WithRangeColors .

func WithRangeLen

func WithRangeLen(val option.RangeVal) Option

WithRangeLen .

func WithRangeSize

func WithRangeSize(val option.RangeVal) Option

WithRangeSize .

func WithRangeThumbBgCirclesNum

func WithRangeThumbBgCirclesNum(val int) Option

WithRangeThumbBgCirclesNum .

func WithRangeThumbBgColors

func WithRangeThumbBgColors(val []string) Option

WithRangeThumbBgColors .

func WithRangeThumbBgDistort

func WithRangeThumbBgDistort(val int) Option

WithRangeThumbBgDistort .

func WithRangeThumbBgSlimLineNum

func WithRangeThumbBgSlimLineNum(val int) Option

WithRangeThumbBgSlimLineNum .

func WithRangeThumbColors

func WithRangeThumbColors(val []string) Option

WithRangeThumbColors .

func WithRangeThumbImageSize

func WithRangeThumbImageSize(val option.Size) Option

WithRangeThumbImageSize .

func WithRangeThumbSize

func WithRangeThumbSize(val option.RangeVal) Option

WithRangeThumbSize .

func WithRangeVerifyLen

func WithRangeVerifyLen(val option.RangeVal) Option

WithRangeVerifyLen .

func WithShadowColor

func WithShadowColor(val string) Option

WithShadowColor .

func WithShadowPoint

func WithShadowPoint(val option.Point) Option

WithShadowPoint .

func WithThumbDisturbAlpha

func WithThumbDisturbAlpha(val float32) Option

WithThumbDisturbAlpha .

func WithUseShapeOriginalColor

func WithUseShapeOriginalColor(val bool) Option

WithUseShapeOriginalColor .

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options defines the configuration options for the captcha

func NewOptions

func NewOptions() *Options

NewOptions .

func (*Options) GetDisabledRangeVerifyLen

func (o *Options) GetDisabledRangeVerifyLen() bool

GetDisabledRangeVerifyLen .

func (*Options) GetDisplayShadow

func (o *Options) GetDisplayShadow() bool

GetDisplayShadow .

func (*Options) GetImageAlpha

func (o *Options) GetImageAlpha() float32

GetImageAlpha .

func (*Options) GetImageSize

func (o *Options) GetImageSize() *option.Size

GetImageSize .

func (*Options) GetIsThumbNonDeformAbility

func (o *Options) GetIsThumbNonDeformAbility() bool

GetIsThumbNonDeformAbility .

func (*Options) GetRangeAnglePos

func (o *Options) GetRangeAnglePos() []*option.RangeVal

GetRangeAnglePos .

func (*Options) GetRangeColors

func (o *Options) GetRangeColors() []string

GetRangeColors .

func (*Options) GetRangeLen

func (o *Options) GetRangeLen() *option.RangeVal

GetRangeLen .

func (*Options) GetRangeSize

func (o *Options) GetRangeSize() *option.RangeVal

GetRangeSize .

func (*Options) GetRangeThumbBgColors

func (o *Options) GetRangeThumbBgColors() []string

GetRangeThumbBgColors .

func (*Options) GetRangeThumbColors

func (o *Options) GetRangeThumbColors() []string

GetRangeThumbColors .

func (*Options) GetRangeThumbSize

func (o *Options) GetRangeThumbSize() *option.RangeVal

GetRangeThumbSize .

func (*Options) GetRangeVerifyLen

func (o *Options) GetRangeVerifyLen() *option.RangeVal

GetRangeVerifyLen .

func (*Options) GetShadowColor

func (o *Options) GetShadowColor() string

GetShadowColor .

func (*Options) GetShadowPoint

func (o *Options) GetShadowPoint() *option.Point

GetShadowPoint .

func (*Options) GetThumbBgCirclesNum

func (o *Options) GetThumbBgCirclesNum() int

GetThumbBgCirclesNum .

func (*Options) GetThumbBgDistort

func (o *Options) GetThumbBgDistort() int

GetThumbBgDistort .

func (*Options) GetThumbBgSlimLineNum

func (o *Options) GetThumbBgSlimLineNum() int

GetThumbBgSlimLineNum .

func (*Options) GetThumbDisturbAlpha

func (o *Options) GetThumbDisturbAlpha() float32

GetThumbDisturbAlpha .

func (*Options) GetThumbImageSize

func (o *Options) GetThumbImageSize() *option.Size

GetThumbImageSize .

func (*Options) GetUseShapeOriginalColor

func (o *Options) GetUseShapeOriginalColor() bool

GetUseShapeOriginalColor .

type Resource

type Resource func(*Resources)

func WithBackgrounds

func WithBackgrounds(images []image.Image) Resource

WithBackgrounds is to set background image

func WithChars

func WithChars(chars map[string][]string) Resource

WithChars is to set characters

func WithFonts

func WithFonts(fonts []*truetype.Font) Resource

WithFonts is to set font

func WithShapes

func WithShapes(shapeMaps map[string]image.Image) Resource

WithShapes is to set shape

func WithThumbBackgrounds

func WithThumbBackgrounds(images []image.Image) Resource

WithThumbBackgrounds is to set thumbnail background image

type Resources

type Resources struct {
	// contains filtered or unexported fields
}

Resources defines the resources for the CAPTCHA

func NewResources

func NewResources() *Resources

NewResources .

Jump to

Keyboard shortcuts

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