qr

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2018 License: Apache-2.0, MIT Imports: 13 Imported by: 0

Documentation

Overview

Package qr can be used to create QR barcodes.

Index

Examples

Constants

View Source
const (
	L200  int = 200
	L300  int = 300
	L500  int = 500
	L600  int = 600
	L800  int = 800
	L1000 int = 1000
	L1500 int = 1500
	L2000 int = 2000
)

常见二维码边长

Variables

This section is empty.

Functions

func Encode

func Encode(content string, level ErrorCorrectionLevel, mode Encoding) (barcode.Barcode, error)

Encode returns a QR barcode with the given content, error correction level and uses the given encoding

Example
f, _ := os.Create("qrcode.png")
defer f.Close()

qrcode, err := Encode("hello world", L, Auto)
if err != nil {
	fmt.Println(err)
} else {
	qrcode, err = barcode.Scale(qrcode, 100, 100)
	if err != nil {
		fmt.Println(err)
	} else {
		png.Encode(f, qrcode)
	}
}
Output:

func Gif

func Gif(content string, ecl ErrorCorrectionLevel, sideLength int, o *gif.Options) (bytes.Buffer, error)

输出gif格式图片字节流

func Img

func Img(content string, ecl ErrorCorrectionLevel, sideLength int) (barcode.Barcode, error)

输出二维码对象 ecl为容错性

func Jpeg

func Jpeg(content string, ecl ErrorCorrectionLevel, sideLength int, o *jpeg.Options) (bytes.Buffer, error)

输出jpeg格式图片字节流

func Png

func Png(content string, ecl ErrorCorrectionLevel, sideLength int) (bytes.Buffer, error)

输出png格式图片字节流

Types

type Encoding

type Encoding byte

Encoding mode for QR Codes.

const (
	// Auto will choose ths best matching encoding
	Auto Encoding = iota
	// Numeric encoding only encodes numbers [0-9]
	Numeric
	// AlphaNumeric encoding only encodes uppercase letters, numbers and  [Space], $, %, *, +, -, ., /, :
	AlphaNumeric
	// Unicode encoding encodes the string as utf-8
	Unicode
)

func (Encoding) String

func (e Encoding) String() string

type ErrorCorrectionLevel

type ErrorCorrectionLevel byte

ErrorCorrectionLevel indicates the amount of "backup data" stored in the QR code

const (
	// L recovers 7% of data
	L ErrorCorrectionLevel = iota
	// M recovers 15% of data
	M
	// Q recovers 25% of data
	Q
	// H recovers 30% of data
	H
)

func (ErrorCorrectionLevel) String

func (ecl ErrorCorrectionLevel) String() string

Jump to

Keyboard shortcuts

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