Documentation ¶
Overview ¶
Package provides an simple, unopinionated API for captcha generation
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadFontFromReader ¶
LoadFontFromReader load an external font from an io.Reader interface.
Types ¶
type Captcha ¶
type Captcha struct { Text string // contains filtered or unexported fields }
Captcha is the result of captcha generation. It has a `Text` field and a private `img` field, which will be used in the `WriteImage` receiver.
func NewCustomGenerator ¶
func NewCustomGenerator(width int, height int, generator func() (anwser string, question string), option ...SetOption) (*Captcha, error)
NewCustomGenerator creates a new captcha based on a custom text generator.
func NewMathExpr ¶
NewMathExpr creates a new captcha. Generates an image with a mathematical expression like `1 + 2`.
func (*Captcha) WriteGIF ¶
WriteGIF encodes the image data into GIF format and writes it to io.Writer. Returns an error possible when encoding GIF.
func (*Captcha) WriteImage ¶
WriteImage encodes image data and writes it to io.Writer. Returns an error possible when encoding PNG.
type Options ¶
type Options struct { // BackgroundColor is captcha image's background color. // By default it is color.Transparent. BackgroundColor color.Color // CharPreset defines the text on the captcha image. // By default: // ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 CharPreset string // TextLength is the length of the captcha text. // By default it is 4. TextLength int // CurveNumber is the number of curves to draw on captcha image. // By default it is 2. CurveNumber int // FontDPI controls DPI (dots per inch) of font. // By default it is 72.0. FontDPI float64 // FontScale controls the scale of font. // By default it is 1.0. FontScale float64 // Noise controls the amount of noise to be drawn. // By default, a noise point is drawn every 28 pixels. // By default it is 1.0. Noise float64 // Palette is the set of colors to chose from. Palette color.Palette // contains filtered or unexported fields }
Options manage captcha generation.