qr

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

README

Go QR encoder package.

go get [-u] github.com/unixdj/qr

Based on rsc.io/qr by Russ Cox. Drop in replacement for package qr. The API of package coding is incompatible.

Improvements to qr.Encode:

  • Automatic mask selection
  • Splitting text into segments to minimise encoded length
  • Kanji mode segments
  • Faster encoding

Added features in package qr:

  • Splitting text into multiple QR codes (Structured Append)
  • Printing QR codes as text
  • Prepending an ECI mode segment to set character encoding
  • Character encodings:
    • UTF-8 (default)
    • UTF-8 with byte mode segments encoded as ISO 8859-1
    • Shift JIS, Shift JISx0213 (Shift JIS-2004)
    • ASCII-compatible eight bit encodings

Packages coding and split:

  • Adding segment encoders
  • Adding input character encodings

Documentation

Overview

Package qr encodes QR codes.

Index

Constants

View Source
const (
	UTF8         = split.UTF8         // UTF-8
	UTF8AsLatin1 = split.UTF8AsLatin1 // UTF-8, byte mode in ISO 8859-1
	ShiftJIS     = split.ShiftJIS     // Shift JIS
	ASCIICompat  = split.ASCIICompat  // ASCII-compatible 8 bit encodings
)

Predefined Charsets.

View Source
const (
	Latin1ECI   = split.Latin1ECI   // ISO 8859-1
	ShiftJISECI = split.ShiftJISECI // Shift JIS
	UTF8ECI     = split.UTF8ECI     // UTF-8
	BinaryECI   = split.BinaryECI   // 8-bit binary data
)

Extended Channel Interpretation assignment numbers.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code struct {
	Bitmap []byte // 1 is black, 0 is white
	Size   int    // number of pixels on a side
	Stride int    // number of bytes per row
	Scale  int    // number of image pixels per QR pixel
}

A Code is a square pixel grid. It implements image.Image and direct PNG encoding.

func Encode

func Encode(text string, level Level) (*Code, error)

Encode returns an encoding of text at the given error correction level.

func EncodeData added in v0.5.0

func EncodeData(data split.Data, level Level) (*Code, error)

EncodeData returns an encoding of data at the given error correction level.

func EncodeMulti added in v0.5.0

func EncodeMulti(header, data split.Data, version coding.Version, level Level) ([]*Code, error)

EncodeMulti returns an encoding of data split across multiple QR codes with the given version and error correction level. If header is not nil, it is added at the beginning of each code.

func EncodeText added in v0.5.0

func EncodeText(text string, c split.Charset, eci uint32, level Level) (*Code, error)

EncodeText returns an encoding of text in the given Charset at the given error correction level. If the Charset is nil, it defaults to UTF8. If eci is not 0, the text is preceded by an ECI mode segment.

func EncodeTextMulti added in v0.5.0

func EncodeTextMulti(text string, c split.Charset, eci uint32, version coding.Version, level Level) ([]*Code, error)

EncodeTextMulti is a combination of EncodeText and EncodeMulti. The ECI mode segment is encoded in each code.

func (*Code) Black

func (c *Code) Black(x, y int) bool

Black returns true if the pixel at (x,y) is black.

func (*Code) Image

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

Image returns an Image displaying the code.

func (*Code) PNG

func (c *Code) PNG() []byte

PNG returns a PNG image displaying the code.

PNG uses a custom encoder tailored to QR codes. Its compressed size is about 4x away from optimal, but it runs about 20x faster than calling png.Encode on c.Image().

func (*Code) Reverse added in v0.5.0

func (c *Code) Reverse() Reversed

Reverse returns a code with colors reversed.

func (*Code) String added in v0.5.0

func (c *Code) String() string

String returns a multiline string containing the code for printing on a dark background.

type Level

type Level int

A Level denotes a QR error correction level. From least to most tolerant of errors, they are L, M, Q, H.

const (
	L Level = iota // 20% redundant
	M              // 38% redundant
	Q              // 55% redundant
	H              // 65% redundant
)

type Reversed added in v0.5.0

type Reversed struct {
	*Code
}

Reversed is a Code with colors reversed.

func (Reversed) Black added in v0.5.0

func (c Reversed) Black(x, y int) bool

Black returns true if the original pixel at (x,y) is white.

func (Reversed) Image added in v0.5.0

func (c Reversed) Image() image.Image

Image returns an Image displaying the reversed code.

func (Reversed) PNG added in v0.5.0

func (c Reversed) PNG() []byte

PNG returns a PNG image displaying the reversed code.

func (Reversed) String added in v0.5.0

func (c Reversed) String() string

String returns a multiline string containing the code for printing on a light background.

Directories

Path Synopsis
Package coding implements low-level QR coding details.
Package coding implements low-level QR coding details.
Package gf256 implements arithmetic over the Galois Field GF(256).
Package gf256 implements arithmetic over the Galois Field GF(256).
Package libqrencode wraps the C libqrencode library.
Package libqrencode wraps the C libqrencode library.
Package split splits strings into QR code segments.
Package split splits strings into QR code segments.

Jump to

Keyboard shortcuts

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