slide

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: Apache-2.0 Imports: 11 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GraphImageErr           = errors.New("graph image is invalid")
	GenerateDataErr         = errors.New("data generation failed")
	ImageTypeErr            = errors.New("tile image must be of type image.Image")
	ShadowImageTypeErr      = errors.New("tile shadow image must be of type image.Image")
	MaskImageTypeErr        = errors.New("tile mask image must be of type image.Image")
	EmptyBackgroundImageErr = errors.New("no background image")
)

Functions

func CheckPoint deprecated

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

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

func Validate added in v2.0.4

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

Validate checks if the point position is within the specified range params:

  • sx: Source X coordinate
  • sy: Source Y coordinate
  • dx: Target X coordinate
  • dy: Target Y coordinate
  • padding: Padding

return: Whether within range

Types

type Block

type Block struct {
	X      int `json:"x"`
	Y      int `json:"y"`
	Width  int `json:"width"`
	Height int `json:"height"`
	Angle  int `json:"angle"`
	// Deprecated: As of 2.1.0, it will be removed, please use [Block.DX].
	TileX int `json:"tile_x"`
	// Deprecated: As of 2.1.0, it will be removed, please use [Block.DY].
	TileY int `json:"tile_y"`
	// Display x,y
	DX int `json:"dx"`
	DY int `json:"dy"`
}

Block defines the block data for the slide CAPTCHA

type Builder

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

Builder defines the interface for building slide CAPTCHAs

func NewBuilder

func NewBuilder(opts ...Option) Builder

NewBuilder creates a new Builder instance params:

  • 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() *Block

GetData gets the block data of the CAPTCHA return: Pointer to block data

func (CaptData) GetMasterImage

func (c CaptData) GetMasterImage() imagedata.JPEGImageData

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

func (CaptData) GetTileImage

func (c CaptData) GetTileImage() imagedata.PNGImageData

GetTileImage gets the tile image return: Tile image in PNG format

type Captcha

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

Captcha defines the interface for slide CAPTCHA

type CaptchaData

type CaptchaData interface {
	GetData() *Block
	GetMasterImage() imagedata.JPEGImageData
	GetTileImage() imagedata.PNGImageData
}

CaptchaData defines the interface for slide CAPTCHA data

type DeadZoneDirectionType

type DeadZoneDirectionType int
const (
	DeadZoneDirectionTypeLeft DeadZoneDirectionType = iota
	DeadZoneDirectionTypeRight
	DeadZoneDirectionTypeTop
	DeadZoneDirectionTypeBottom
)

type DrawBlock

type DrawBlock struct {
	Block  *Block
	X      int
	Y      int
	Image  image.Image
	Width  int
	Height int
	Angle  int
}

DrawBlock defines the parameters for drawing slide CAPTCHA blocks

type DrawImage

type DrawImage interface {
	DrawWithNRGBA(params *DrawImageParams) (img image.Image, bgImg image.Image, err error)
	DrawWithTemplate(params *DrawTplImageParams) (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
	Alpha             float32
	CaptchaDrawBlocks []*DrawBlock
}

DrawImageParams defines the parameters for drawing the main image

type DrawTplImageParams

type DrawTplImageParams struct {
	X                int
	Y                int
	Width            int
	Height           int
	Background       image.Image
	MaskImage        image.Image
	Alpha            float32
	CaptchaDrawBlock *DrawBlock
}

DrawTplImageParams defines the parameters for drawing the template image (tile)

type GraphImage

type GraphImage struct {
	OverlayImage image.Image
	ShadowImage  image.Image
	MaskImage    image.Image
}

GraphImage defines the graph resources for the slide CAPTCHA

type Mode

type Mode int
const (
	ModeBasic Mode = iota
	ModeDrag
)

type Option

type Option func(*Options)

func WithEnableGraphVerticalRandom

func WithEnableGraphVerticalRandom(val bool) Option

WithEnableGraphVerticalRandom .

func WithGenGraphNumber

func WithGenGraphNumber(val int) Option

WithGenGraphNumber .

func WithImageAlpha

func WithImageAlpha(val float32) Option

WithImageAlpha .

func WithImageSize

func WithImageSize(val option.Size) Option

WithImageSize .

func WithRangeDeadZoneDirections

func WithRangeDeadZoneDirections(val []DeadZoneDirectionType) Option

WithRangeDeadZoneDirections .

func WithRangeGraphAnglePos

func WithRangeGraphAnglePos(vals []option.RangeVal) Option

WithRangeGraphAnglePos .

func WithRangeGraphSize

func WithRangeGraphSize(val option.RangeVal) Option

WithRangeGraphSize .

type Options

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

Options .

func NewOptions

func NewOptions() *Options

NewOptions .

func (*Options) GetImageAlpha

func (o *Options) GetImageAlpha() float32

GetImageAlpha .

func (*Options) GetImageSize

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

GetImageSize .

func (*Options) GetRangeDeadZoneDirections

func (o *Options) GetRangeDeadZoneDirections() []DeadZoneDirectionType

GetRangeDeadZoneDirections .

func (*Options) GetRangeGraphAnglePos

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

GetRangeGraphAnglePos .

func (*Options) GetRangeGraphSize

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

GetRangeGraphSize .

type Resource

type Resource func(*Resources)

func WithBackgrounds

func WithBackgrounds(images []image.Image) Resource

WithBackgrounds sets the background images params:

  • images: List of background images

return: Resource function

func WithGraphImages

func WithGraphImages(images []*GraphImage) Resource

WithGraphImages sets the graph images params:

  • images: List of graph images

return: Resource function

type Resources

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

Resources defines the resource collection for the slide CAPTCHA

func NewResources

func NewResources() *Resources

NewResources creates a new Resources instance return: Pointer to a Resources instance

Jump to

Keyboard shortcuts

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