qr

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 11 Imported by: 1

README

qr

qr is a library for generating QR Codes in pure Go.

go get github.com/AlexEidt/qr

Usage

qrcode, err := qr.NewQRCode("QR Code", &qr.Options{Error: "H"})
if err != nil {
    panic(err)
}

qrcode.Render("qr.png", 10)

Below are the functions available for a QRCode.

qr.NewQRCode(data string, options *qr.Options) (*qr.QRCode, error)

Version() int
Mode() int // 1: numeric, 2: alphanumeric, 4: byte
ErrorLevel() string // L, M, Q, H
Bitmap() *qr.Bitmap
Render(filename string, scale int) error // .png, .jpg, .svg supported

Options

When building a QR Code, certain parameters can be specified such as the Version, Mode and Error Correction Level.

type Options struct {
	Version int
	Mode    int
	Error   string
}
Parameter Description
Version The version of the QR Code to be generated. Must be between 1 and 40. Defaults to lowest version that fits the given data.
Mode The mode of the QR Code to be generated. Must be qr.Numeric, qr.AlphaNum, or qr.Byte. The best fit is found based on the given data. See the Supported Modes section below for the characters that can be used in each mode.
Error The error correction level of the QR Code to be generated. Must be L, M, Q, or H. Defaults to L. Level L can correct ~7% of errors, M can correct ~15% of errors, Q can correct ~25% of errors, and H can correct ~30% of errors.

Supported Modes

Currently, only Numeric, Alphanumeric and Binary modes are supported for data encoding.

Mode Character Set
Numeric 0123456789
Alphanumeric 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:
Binary ISO/IEC 8859-1

Notes

  • Kanji mode is not supported.
  • Structured Append mode is not supported.
  • Extended Channel Interpretations (ECI) mode is not supported.
  • Model 1 QR Codes are not supported.

Acknowledgements

The following resources were helpful in building this library:

Documentation

Index

Constants

View Source
const (
	Numeric  = 1
	AlphaNum = 2
	Byte     = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitmap

type Bitmap struct {
	// contains filtered or unexported fields
}

func NewBitmap

func NewBitmap(width, height int) *Bitmap

func (*Bitmap) At

func (b *Bitmap) At(x, y int) bool

func (*Bitmap) Copy

func (b *Bitmap) Copy() *Bitmap

func (*Bitmap) Fill

func (b *Bitmap) Fill(x, y, w, h int, value bool)

func (*Bitmap) Height

func (b *Bitmap) Height() int

func (*Bitmap) Invert

func (b *Bitmap) Invert()

func (*Bitmap) Place

func (b *Bitmap) Place(x, y int, other *Bitmap)

func (*Bitmap) Set

func (b *Bitmap) Set(x, y int, value bool)

func (*Bitmap) Width

func (b *Bitmap) Width() int

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer() *Buffer

func (*Buffer) Add

func (b *Buffer) Add(val, size int)

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

func (*Buffer) Clear

func (b *Buffer) Clear()

func (*Buffer) Size

func (b *Buffer) Size() int

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) Write

func (b *Buffer) Write(data string)

type Options

type Options struct {
	Version int
	Mode    int
	Error   string
}

type QRCode

type QRCode struct {
	// contains filtered or unexported fields
}

func NewQRCode

func NewQRCode(data string, options *Options) (*QRCode, error)

func (*QRCode) Bitmap

func (qr *QRCode) Bitmap() *Bitmap

func (*QRCode) ErrorLevel

func (qr *QRCode) ErrorLevel() string

func (*QRCode) Mode

func (qr *QRCode) Mode() int

func (*QRCode) Render

func (qr *QRCode) Render(filename string, scale int) error

func (*QRCode) Version

func (qr *QRCode) Version() int

Jump to

Keyboard shortcuts

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