kmgQrcode

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

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

Go to latest
Published: Nov 5, 2018 License: MIT Imports: 10 Imported by: 0

README

Description

GoDoc GitHub issues GitHub stars GitHub forks MIT License

a golang qrcode writer

A QR Code is a matrix (two-dimensional) barcode. Arbitrary content may be encoded.

A QR Code contains error recovery information to aid reading damaged or obscured codes. There are four levels of error recovery: qrcode.{Low, Medium, High, Highest}. QR Codes with a higher recovery level are more robust to damage, at the cost of being physically larger.

The maximum capacity of a QR Code varies according to the content encoded and the error recovery level. The maximum capacity is 2,953 bytes, 4,296 alphanumeric characters, 7,089 numeric digits, or a combination of these.

This package implements a subset of QR Code 2005, as defined in ISO/IEC 18004:2006.

Example

package main

import (
	"github.com/bronze1man/kmgQrcode"
	"io/ioutil"
)

func main(){
	resp:= kmgQrcode.MustEncode(kmgQrcode.EncodeReq{
		Content: "https://www.google.com/",
	})
	err:=ioutil.WriteFile("tmp.png",resp.PngContent,0777)
	if err!=nil{
		panic(err)
	}
}

Notice

  • It can not read qrcode into text, it can only translate qrcode text into png byte slice.
  • fork from https://github.com/skip2/go-qrcode , with following change:
    • Make the package name easy to remember and import.
    • Simplify the caller interface, leave only one function kmgQrcode.MustEncode .
    • Delete surrounding blank, make the qrcode part as large as possible.(use float64 instead of int to generate image.)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EncodeReq

type EncodeReq struct {
	Content string        `json:",omitempty"`
	Level   RecoveryLevel `json:",omitempty"` // 冗余比例,默认 Highest
	PngSize int           `json:",omitempty"` // 输出的png的长宽,会输出一个正方形的图形,所以长宽都一样。 默认 256

	IsOutputDataUrl bool `json:",omitempty"` // 输出Data url,(就不输出 png了)

	MemoryCacher *EncodeV2Cacher `json:"-"` // 在进程内存中缓存生成qrcode的请求和结果。以便下次可以快速使用。
	CacheKey     string          `json:",omitempty"`

	PngUseBufferPool    bool                 `json:",omitempty"` // 是否使用 UsePngBufferPool,这个东西可以减少alloc,但是会产生一个一直不释放的内存占用
	PngCompressionLevel png.CompressionLevel `json:",omitempty"`
}

type EncodeResp

type EncodeResp struct {
	PngContent []byte
	DataUrl    string
}

func MustEncode

func MustEncode(req EncodeReq) (resp EncodeResp)

type EncodeV2Cacher

type EncodeV2Cacher struct {
	MaxCacheSize int // 默认 1000,创建之后不要修改。
	// contains filtered or unexported fields
}

func (*EncodeV2Cacher) GetByKey

func (c *EncodeV2Cacher) GetByKey(key string) (resp EncodeResp, ok bool)

func (*EncodeV2Cacher) SetByKey

func (c *EncodeV2Cacher) SetByKey(key string, resp EncodeResp)

type RecoveryLevel

type RecoveryLevel int

Error detection/recovery capacity.

There are several levels of error detection/recovery capacity. Higher levels of error recovery are able to correct more errors, with the trade-off of increased symbol size.

const (
	// Level L: 7% error recovery.
	Low RecoveryLevel = 1

	// Level M: 15% error recovery. Good default choice.
	Medium RecoveryLevel = 2

	// Level Q: 25% error recovery.
	High RecoveryLevel = 3

	// Level H: 30% error recovery.
	Highest RecoveryLevel = 4
)

Directories

Path Synopsis
Package bitset implements an append only bit array.
Package bitset implements an append only bit array.
Package reedsolomon provides error correction encoding for QR Code 2005.
Package reedsolomon provides error correction encoding for QR Code 2005.

Jump to

Keyboard shortcuts

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