qrcode

package module
v0.0.0-...-7b1a97f Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2021 License: MIT Imports: 6 Imported by: 0

README

go-qrcode

Golang library to generate QR code

go report card MIT license Go.Dev reference codecov nishant8887

Getting started

Import

To import the library add the following import to your code.

import "github.com/nishant8887/go-qrcode"
Create a new QR code

Creating a new QR code is very simple.

code, err := qrcode.New("HELLO WORLD", qrcode.Q)
if err != nil {
    return err
}
Get code matrix

Get the 2D boolean array representing QR code.

m := code.Matrix()
Get code image

Get the image form of QR code.

imageFile, err := os.Create("image.png")
if err != nil {
    return err
}

img := code.Image()
err := png.Encode(imageFile, code.Image())
if err != nil {
    return err
}

Tools

Go-qrcode provides handy command line tool.

  • qrgenerate - Generates QR code image from text
go install github.com/nishant8887/go-qrcode/cmd/qrgenerate
qrgenerate --help
  • Nice tutorial for QR code reference
  • Guide for creating a QR code

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ecl

type Ecl int

Ecl - error correction level according to the QR code specifications

const (
	L Ecl = 1
	M Ecl = 0
	Q Ecl = 3
	H Ecl = 2
)

Four error correction levels:

L - Recovers 7% of data

M - Recovers 15% of data

Q - Recovers 25% of data

H - Recovers 30% of data

type Mode

type Mode int

Mode - mode according to the QR code specifications

const (
	Numeric      Mode = 1
	Alphanumeric Mode = 2
	Byte         Mode = 4
	Kanji        Mode = 8
)

Modes according to the QR code specifications

1. Numeric

2. Alphanumeric

3. Byte

4. Kanji

type QRCode

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

QRCode - generated QRCode from the data

func New

func New(data string, ecl Ecl) (*QRCode, error)

New creates a QR code for given string and error correction level

func (*QRCode) Ecl

func (c *QRCode) Ecl() Ecl

Ecl - returns the error correction level of the generated QR code

func (*QRCode) Image

func (c *QRCode) Image() image.Image

Image - returns the image of the generated QR code

func (*QRCode) Mask

func (c *QRCode) Mask() int

Mask - returns the mask used for the generated QR code

func (*QRCode) Matrix

func (c *QRCode) Matrix() [][]bool

Matrix - returns the 2D boolean array for the generated QR code

func (*QRCode) Mode

func (c *QRCode) Mode() Mode

Mode - returns the mode of the generated QR code

func (*QRCode) Size

func (c *QRCode) Size() int

Size - returns the size of the QR code's grid

func (*QRCode) Version

func (c *QRCode) Version() int

Version - returns the version of the generated QR code

type RSEncoder

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

RSEncoder - Reed-solomon encoder for QR code

func NewRSEncoder

func NewRSEncoder(errorCodewords int) *RSEncoder

NewRSEncoder - New reed-solomon encoder

func (*RSEncoder) Encode

func (e *RSEncoder) Encode(block []byte) ([]byte, error)

Encode - encodes the code word to generate reed-solomon error code word

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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