Documentation
¶
Index ¶
- func LoadFont(fontData []byte) error
- func LoadFontFromReader(reader io.Reader) error
- type Data
- func (data *Data) WriteGIF(w io.Writer, o *gif.Options) error
- func (data *Data) WriteGIFFile(fp string) error
- func (data *Data) WriteImage(w io.Writer) error
- func (data *Data) WriteJPG(w io.Writer, o *jpeg.Options) error
- func (data *Data) WriteJPGFile(fp string) error
- func (data *Data) WritePNGFile(fp string) error
- type Options
- type SetOption
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 Data ¶
Data is the result of captcha generation. It has a `Text` field and a private `img` field that will be used in `WriteImage` receiver.
func New ¶
New creates a new captcha. It returns captcha data and any freetype drawing error encountered.
func NewCustomGenerator ¶
func NewCustomGenerator( width int, height int, generator func() (anwser string, question string), option ...SetOption, ) (*Data, error)
NewCustomGenerator creates a new captcha based on a custom text generator.
func NewMathExpr ¶
NewMathExpr creates a new captcha. It will generate a image with a math expression like `1 + 2`.
func (*Data) WriteGIF ¶
WriteGIF encodes image data in GIF format and writes to an io.Writer. It returns possible error from GIF encoding.
func (*Data) WriteGIFFile ¶
WriteGIFFile 将图像保存为GIF文件
func (*Data) WriteImage ¶
WriteImage encodes image data and writes to an io.Writer. It returns possible error from PNG encoding.
func (*Data) WriteJPG ¶
WriteJPG encodes image data in JPEG format and writes to an io.Writer. It returns possible error from JPEG encoding.
func (*Data) WriteJPGFile ¶
WriteJPGFile 将图像保存为JPG文件
func (*Data) WritePNGFile ¶
WritePNGFile 将图像保存为PNG文件
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
// FontDPI controls DPI (dots per inch) of font.
// The default is 72.0.
FontDPI float64
// FontScale controls the scale of font.
// The default is 1.0.
FontScale float64
// Noise controls the number of noise drawn.
// A noise dot is drawn for every 28 pixel by default.
// The default 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 details.