gocaptcha

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2020 License: MIT Imports: 20 Imported by: 0

README

gocaptcha

图片验证码,因需求原因,在https://github.com/steambap/captcha的基础上简化修改而来,因使用要求与其有较大的不同,所以特此新建

字体使用go-bindata,字体在网上下载的两种字体,其版权问题不清楚

panic "integer divide by zero"

如果在github.com/golang/freetype/truetype/hint.go的函数mulDiv出除数不能为0的panic是因为字体造成,请换其他字体

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Data

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

func New

func New(options *Options) (*Data, error)

New 生成验证码

func (*Data) BinaryEncoding added in v1.0.1

func (data *Data) BinaryEncoding() []byte

func (*Data) EncodeB64string added in v1.0.2

func (data *Data) EncodeB64string() string

func (*Data) WriteImage

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

WriteImage 输出图片

func (*Data) WriteTo added in v1.0.1

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

type Options

type Options struct {
	CharPreset      string      // 验证码预设的字符
	Length          int         // 验证码位数
	Width           int         // 验证码宽
	Height          int         // 验证码高
	Curve           int         // 曲线数 0 为不设曲线,默认0
	BackgroundColor color.Color // 背景色,默认黑色全透明
	FontDPI         float64     // 字体DPI,默认72.0
	FontScale       float64     // 字体比例系数,默认1.0
	Noise           float64     // 噪点密集度系数,默认1.0
}

Jump to

Keyboard shortcuts

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