Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/lifei6671/gocaptcha

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/lifei6671/gocaptcha

  • v1.0.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

gocaptcha

一个简单的Go语言实现的验证码

图片实例

image image image image

简介

基于Golang实现的图片验证码生成库,可以实现随机字母个数,随机直线,随机噪点等。可以设置任意多字体,每个验证码随机选一种字体展示。

实例

使用:
	go get github.com/lifei6671/gocaptcha
使用的类库
	go get github.com/golang/freetype
	go get github.com/golang/freetype/truetype
	go get golang.org/x/image
代码

具体实例可以查看example目录,有生成的验证码图片。

	
func Get(w http.ResponseWriter, r *http.Request) {
	captchaImage := gocaptcha.New(dx, dy, gocaptcha.RandLightColor())
	err := captchaImage.
		DrawBorder(gocaptcha.RandDeepColor()).
		DrawNoise(gocaptcha.NoiseDensityHigh, gocaptcha.NewTextNoiseDrawer(gocaptcha.DefaultDPI)).
		DrawNoise(gocaptcha.NoiseDensityLower, gocaptcha.NewPointNoiseDrawer()).
		DrawLine(gocaptcha.NewBezier3DLine(), gocaptcha.RandDeepColor()).
		DrawText(gocaptcha.NewTwistTextDrawer(gocaptcha.DefaultDPI, gocaptcha.DefaultAmplitude, gocaptcha.DefaultFrequency), gocaptcha.RandText(4)).
		DrawLine(gocaptcha.NewBeeline(), gocaptcha.RandDeepColor()).
		//DrawLine(gocaptcha.NewHollowLine(), gocaptcha.RandLightColor()).
		DrawBlur(gocaptcha.NewGaussianBlur(), gocaptcha.DefaultBlurKernelSize, gocaptcha.DefaultBlurSigma).
		Error
	
	if err != nil {
		fmt.Println(err)
	}
	
	_ = captchaImage.Encode(w, gocaptcha.ImageFormatJpeg)
}

// 初始化字体
func init() {
	err := gocaptcha.SetFontPath("../fonts/")
	if err != nil {
		panic(err)
	}
}

FAQs

Package last updated on 20 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc