captcha

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2017 License: MIT Imports: 11 Imported by: 1

README

Package captcha provides a simple API for captcha generation

GoDoc Build Status codecov Go Report Card

install

go get github.com/steambap/captcha

usage

func handle(w http.ResponseWriter, r *http.Request) {
	// create a captcha of 150x50px
	data, _ := captcha.New(150, 50)

	// session come from other library such as gorilla/sessions
	session.Values["captcha"] = data.Text
	session.Save(r, w)
	// send image data to client
	data.WriteTo(w)
}

documentation | example

sample image

image

License

MIT

Documentation

Overview

Package captcha provides a simple API for captcha generation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	// Text is captcha solution
	Text string
	// contains filtered or unexported fields
}

Data is the result of captcha generation. It has a `Text` field and a private `img` field that will be used in `WriteTo` receiver

func New

func New(width int, height int, option ...SetOption) (*Data, error)

New creates a new captcha. It returns captcha data and any freetype drawing error encountered

func (*Data) WriteTo

func (data *Data) WriteTo(w io.Writer) error

WriteTo encodes image data and writes to an io.Writer. It returns possible error from PNG encoding

type Options

type Options struct {
	// BackgroundColor is captcha image's background color.
	// It defaults to color.Transparent.
	BackgroundColor color.Color
	// CharPreset decides what text will be on captcha image.
	// It defaults to digit 0-9 and all English alphabet.
	// ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
	CharPreset string
	// TextLength is the length of captcha text.
	// It defaults to 4.
	TextLength int
	// CurveNumber is the number of curves to draw on captcha image.
	// It defaults to 2.
	CurveNumber int
	// contains filtered or unexported fields
}

Options manage captcha generation details.

type SetOption

type SetOption func(*Options)

SetOption is a function that can be used to modify default options.

Directories

Path Synopsis
basic Module

Jump to

Keyboard shortcuts

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