capcha

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

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

Go to latest
Published: Oct 5, 2019 License: GPL-3.0, GPL-3.0-or-later Imports: 17 Imported by: 0

README

练习验证码

基本用法:

package main

import (
	"gitea.com/iwhot/capcha"
	"os"
)

func main() {
	f, _ := os.OpenFile("rgb.png", os.O_WRONLY|os.O_CREATE, 0600)
    defer f.Close()
    img := capcha.NewCapcha(f,150,30,100)
    img.Writer = f
    //生成验证码
    code := capcha.RandomText(4)
    img.GetCapcha(code,"png")
}

或者:

http.HandleFunc("/pic", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type","image/png")
		img := capcha.NewCapcha(w,150,30,100)
		//生成验证码
		code := capcha.RandomText(4)
		img.GetCapcha(code,"png")
	})
	log.Fatal(http.ListenAndServe(":8080",nil))

Documentation

Index

Constants

View Source
const (
	IMGPNG  = "png"
	IMGGif  = "gif"
	IMGJPEG = "jpeg"
)

Variables

This section is empty.

Functions

func NewCapcha

func NewCapcha(w io.Writer, with, height, comp int) *capcha

创建验证码对象

func RandDeepColor

func RandDeepColor() color.RGBA

随机生成深色系.

func RandomColor

func RandomColor() color.RGBA

随机颜色

func RandomText

func RandomText(num int) string

生成随机验证码

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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