libgocaptcha

package
v0.0.0-...-7526ba0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: MIT Imports: 12 Imported by: 0

README

GoDoc

Documentation

Index

Constants

View Source
const (
	// Standard width and height of a captcha image.
	StdWidth  = 240
	StdHeight = 80
)
View Source
const (
	MODULE_DIGIT = 10
	MODULE_UPPER = 36
	MODULE_LOWER = 62
)

These constants are used to set the used character ranges in the captcha image

Variables

This section is empty.

Functions

func AddFont

func AddFont(name string, f *Font)

Add a font to the internal list of available fonts. The name is used to select the font later. The first font you add is selected automatically

func Digit2Rune

func Digit2Rune(d byte) rune

func RandomDigits

func RandomDigits(length int) []byte

RandomDigits returns a byte slice of the given length containing pseudorandom numbers in range 0-module. The slice can be used as a captcha solution.

func RandomId

func RandomId() string

RandomId returns a new random id string.

func Rune2Digit

func Rune2Digit(c rune) byte

func SelectFont

func SelectFont(name string)

Select a font by the name it was added with AddFont If no font with that name exists, the selected font remains unchanged

func SetCharacterRange

func SetCharacterRange(rang byte)

Set the desired character ranges for the captcha image. For example:

captcha.SetCharacterRange(captcha.MODULE_LOWER)

would use 0-9, A-Z and a-z The default is MODULE_UPPER which means 0-9 and A-Z

Types

type Font

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

func LoadFontFromFile

func LoadFontFromFile(fname string) *Font

Load a font created by github.com/chenzihaojie/captcha/fontgen returns the for usage int AddFont, and an error, if the font can't be loaded.

type Image

type Image struct {
	*image.RGBA
	// contains filtered or unexported fields
}

func NewImage

func NewImage(id string, digits []byte, width, height int) *Image

NewImage returns a new captcha image of the given width and height with the given digits, where each digit must be in range 0-61.

func (*Image) WriteTo

func (m *Image) WriteTo(w io.Writer) (int64, error)

WriteTo writes captcha image in PNG format into the given writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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