qrcode

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(content string, level RecoveryLevel, size int) ([]byte, error)

Encode a QR Code and return a raw PNG image.

size is both the image width and height in pixels. If size is too small then a larger image is silently returned. Negative values for size cause a variable sized image to be returned: See the documentation for Image().

To serve over HTTP, remember to send a Content-Type: image/png header.

func WriteColorFile

func WriteColorFile(content string, level RecoveryLevel, size int, background,
	foreground color.Color, filename string) error

WriteColorFile encodes, then writes a QR Code to the given filename in PNG format. With WriteColorFile you can also specify the colors you want to use.

size is both the image width and height in pixels. If size is too small then a larger image is silently written. Negative values for size cause a variable sized image to be written: See the documentation for Image().

func WriteFile

func WriteFile(content string, level RecoveryLevel, size int, filename string) error

WriteFile encodes, then writes a QR Code to the given filename in PNG format.

size is both the image width and height in pixels. If size is too small then a larger image is silently written. Negative values for size cause a variable sized image to be written: See the documentation for Image().

Types

type Bitset

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

Bitset stores an array of bits.

func Clone

func Clone(from *Bitset) *Bitset

Clone returns a copy.

func EncodeBit

func EncodeBit(data *Bitset, numECBytes int) *Bitset

Encode data for QR Code 2005 using the appropriate Reed-Solomon code.

numECBytes is the number of error correction bytes to append, and is determined by the target QR Code's version and error correction level.

ISO/IEC 18004 table 9 specifies the numECBytes required. e.g. a 1-L code has numECBytes=7.

func NewBit

func NewBit(v ...bool) *Bitset

New returns an initialised Bitset with optional initial bits v.

func NewFromBase2String

func NewFromBase2String(b2string string) *Bitset

NewFromBase2String constructs and returns a Bitset from a string. The string consists of '1', '0' or ' ' characters, e.g. "1010 0101". The '1' and '0' characters represent true/false bits respectively, and ' ' characters are ignored.

The function panics if the input string contains other characters.

func (*Bitset) Append

func (b *Bitset) Append(other *Bitset)

Append bits copied from |other|.

The new length is b.Len() + other.Len().

func (*Bitset) AppendBools

func (b *Bitset) AppendBools(bits ...bool)

AppendBools appends bits to the Bitset.

func (*Bitset) AppendByte

func (b *Bitset) AppendByte(value byte, numBits int)

AppendByte appends the numBits least significant bits from value.

func (*Bitset) AppendBytes

func (b *Bitset) AppendBytes(data []byte)

AppendBytes appends a list of whole bytes.

func (*Bitset) AppendNumBools

func (b *Bitset) AppendNumBools(num int, value bool)

AppendNumBools appends num bits of value value.

func (*Bitset) AppendUint32

func (b *Bitset) AppendUint32(value uint32, numBits int)

AppendUint32 appends the numBits least significant bits from value.

func (*Bitset) At

func (b *Bitset) At(index int) bool

At returns the value of the bit at |index|.

func (*Bitset) Bits

func (b *Bitset) Bits() []bool

Bits returns the contents of the Bitset.

func (*Bitset) ByteAt

func (b *Bitset) ByteAt(index int) byte

ByteAt returns a byte consisting of upto 8 bits starting at index.

func (*Bitset) Equals

func (b *Bitset) Equals(other *Bitset) bool

Equals returns true if the Bitset equals other.

func (*Bitset) Len

func (b *Bitset) Len() int

Len returns the length of the Bitset in bits.

func (*Bitset) String

func (b *Bitset) String() string

String returns a human readable representation of the Bitset's contents.

func (*Bitset) Substr

func (b *Bitset) Substr(start int, end int) *Bitset

Substr returns a substring, consisting of the bits from indexes start to end.

type QRCode

type QRCode struct {
	// Original content encoded.
	Content string

	// QR Code type.
	Level         RecoveryLevel
	VersionNumber int

	// User settable drawing options.
	ForegroundColor color.Color
	BackgroundColor color.Color

	// Disable the QR Code border.
	DisableBorder bool
	// contains filtered or unexported fields
}

A QRCode represents a valid encoded QRCode.

func New

func New(content string, level RecoveryLevel) (*QRCode, error)

New constructs a QRCode.

var q *qrcode.QRCode
q, err := qrcode.New("my content", qrcode.Medium)

An error occurs if the content is too long.

func NewWithForcedVersion

func NewWithForcedVersion(content string, version int, level RecoveryLevel) (*QRCode, error)

NewWithForcedVersion constructs a QRCode of a specific version.

var q *qrcode.QRCode
q, err := qrcode.NewWithForcedVersion("my content", 25, qrcode.Medium)

An error occurs in case of invalid version.

func (*QRCode) Bitmap

func (q *QRCode) Bitmap() [][]bool

Bitmap returns the QR Code as a 2D array of 1-bit pixels.

bitmap[y][x] is true if the pixel at (x, y) is set.

The bitmap includes the required "quiet zone" around the QR Code to aid decoding.

func (*QRCode) Image

func (q *QRCode) Image(size int) image.Image

Image returns the QR Code as an image.Image.

A positive size sets a fixed image width and height (e.g. 256 yields an 256x256px image).

Depending on the amount of data encoded, fixed size images can have different amounts of padding (white space around the QR Code). As an alternative, a variable sized image can be generated instead:

A negative size causes a variable sized image to be returned. The image returned is the minimum size required for the QR Code. Choose a larger negative number to increase the scale of the image. e.g. a size of -5 causes each module (QR Code "pixel") to be 5px in size.

func (*QRCode) PNG

func (q *QRCode) PNG(size int) ([]byte, error)

PNG returns the QR Code as a PNG image.

size is both the image width and height in pixels. If size is too small then a larger image is silently returned. Negative values for size cause a variable sized image to be returned: See the documentation for Image().

func (*QRCode) ToSmallString

func (q *QRCode) ToSmallString(inverseColor bool) string

ToSmallString produces a multi-line string that forms a QR-code image, a factor two smaller in x and y then ToString.

func (*QRCode) ToString

func (q *QRCode) ToString(inverseColor bool) string

ToString produces a multi-line string that forms a QR-code image.

func (*QRCode) Write

func (q *QRCode) Write(size int, out io.Writer) error

Write writes the QR Code as a PNG image to io.Writer.

size is both the image width and height in pixels. If size is too small then a larger image is silently written. Negative values for size cause a variable sized image to be written: See the documentation for Image().

func (*QRCode) WriteFile

func (q *QRCode) WriteFile(size int, filename string) error

WriteFile writes the QR Code as a PNG image to the specified file.

size is both the image width and height in pixels. If size is too small then a larger image is silently written. Negative values for size cause a variable sized image to be written: See the documentation for Image().

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 = iota

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

	// Level Q: 25% error recovery.
	High

	// Level H: 30% error recovery.
	Highest
)

Jump to

Keyboard shortcuts

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