gocaptcha

package module
v0.0.0-...-ec67e1b Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2014 License: MIT Imports: 11 Imported by: 0

README

gocaptcha

golang captcha lib

Install
go get github.com/l2x/gocaptcha
Example
package main

import (
    "bufio"
    "fmt"
    "github.com/l2x/gocaptcha"
    "io"
    "os"
)

func main() {
    capt := gocaptcha.New()
    f, txt, err := capt.Create()
    if err != nil {
        fmt.Println(err)
        return
    }

    fo, err := os.Create("out.png")
    if err != nil {
        panic(err)
    }
    // close fo on exit and check for its returned error
    defer func() {
        if err := fo.Close(); err != nil {
            panic(err)
        }
    }()
    // make a write buffer
    w := bufio.NewWriter(fo)

    // make a buffer to keep chunks that are read
    buf := make([]byte, 1024)
    for {
        // read a chunk
        n, err := f.Read(buf)
        if err != nil && err != io.EOF {
            panic(err)
        }
        if n == 0 {
            break
        }

        // write a chunk
        if _, err := w.Write(buf[:n]); err != nil {
            panic(err)
        }
    }

    if err = w.Flush(); err != nil {
        panic(err)
    }

    fmt.Println("Wrote out.png OK. text is ", txt)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capthca

type Capthca struct {
	Dpi      float64
	Font     string
	FontSize float64
	Width    int
	Height   int
	Length   int
}

func New

func New() *Capthca

func (*Capthca) Config

func (c *Capthca) Config(conf map[string]interface{})

func (*Capthca) Create

func (c *Capthca) Create() (*bytes.Buffer, string, error)

Directories

Path Synopsis
example
1
2

Jump to

Keyboard shortcuts

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