Coder Social home page Coder Social logo

verifycode's Introduction

例子:

package main
import (
  "fmt"
  "os"
  "image/png"
  "github.com/456vv/verifycode"
)
func main(){
    //验证码颜色
    c := []string{"#ff8080FF", "#00ff0000", "#8080c0FD"}
    colors, err := verifycode.NewColor(c)
    if err != nil {
        fmt.Println("NewColor: %v", err)
        os.Exit(-1)
    }
    //验证码背景
    b := []string{"#804040FF"}
    backgrounds, err := verifycode.NewColor(b)
    if err != nil {
        fmt.Println("NewColor: %v", err)
        os.Exit(-1)
    }
    //字体
    f := []string{"0.ttf"}
    fonts, err := verifycode.NewFont(f)
    if err != nil {
        fmt.Println("NewFont: %v", err)
        os.Exit(-1)
    }
    verifyCode := verifycode.NewVerifyCode()
    verifyCode.SetDPI(72)           //也可以不用设置这个
    verifyCode.SetColor(colors)
    verifyCode.SetBackground(backgrounds)
    verifyCode.SetFont(fonts)
    verifyCode.SetWidthWithHeight(500, 200) // 宽500px,高200px
    verifyCode.SetFontSize(200)
    verifyCode.SetHinting(false)    //也可以不用设置这个
    verifyCode.SetKerning(-100, 100)    //随机字距,最小-100,最大100
    file, err := os.Create("tmpTest.png")
    if err != nil {
        fmt.Println("创建文件出错 %v", err)
        os.Exit(-1)
    }
    err = verifyCode.PNG("ABCD", file)
    if err != nil {
        fmt.Println("生成验证码出错 %v", err)
        os.Exit(-1)
    }
}

verifycode's People

Contributors

456vv avatar

Watchers

Vicever avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.