Documentation
¶
Overview ¶
Package encoder provides functionality for generating, formatting, and exporting QR codes. It handles data encoding, error correction, and rendering the final QR code into various formats such as images, bit matrices, and terminal strings.
Index ¶
- Constants
- func Element(data byte) gfElement
- func Encode(content string, level RecoveryLevel, size int) ([]byte, error)
- func NewGFPolyOperator() polyOperator
- func WriteColorFile(content string, level RecoveryLevel, size int, ...) error
- func WriteFile(content string, level RecoveryLevel, size int, filename string) error
- type Bit
- type Bitset
- func (b *Bitset) Append(other *Bitset)
- func (b *Bitset) AppendBits(bits ...Bit)
- func (b *Bitset) AppendBools(bits ...bool)
- func (b *Bitset) AppendByte(value byte, numBits int)
- func (b *Bitset) AppendBytes(data []byte)
- func (b *Bitset) AppendNumBools(num int, value bool)
- func (b *Bitset) AppendUint32(value uint32, numBits int)
- func (b *Bitset) At(index int) bool
- func (b *Bitset) Bits() []Bit
- func (b *Bitset) ByteAt(index int) byte
- func (b *Bitset) Equals(other *Bitset) bool
- func (b *Bitset) Len() int
- func (b *Bitset) String() string
- func (b *Bitset) Substr(start int, end int) *Bitset
- type QRCode
- func (q *QRCode) Bitmap() [][]bool
- func (q *QRCode) Image(size int) image.Image
- func (q *QRCode) PNG(size int) []byte
- func (q *QRCode) ToSmallString(inverseColor bool) string
- func (q *QRCode) ToString(inverseColor bool) string
- func (q *QRCode) WithColors(foreground, background color.Color) *QRCode
- func (q *QRCode) WithNoBorder() *QRCode
- func (q *QRCode) Write(size int, out io.Writer) error
- func (q *QRCode) WriteFile(size int, filename string) error
- func (q *QRCode) WriteFileWithoutSize(filename string) error
- type RecoveryLevel
Constants ¶
const DefaultFileSize = 256
DefaultFileSize defines the standard dimensions used when saving a QR code without a specified size.
Variables ¶
This section is empty.
Functions ¶
func Element ¶
func Element(data byte) gfElement
Element converts a standard byte value into a Galois Field element.
func Encode ¶
func Encode(content string, level RecoveryLevel, size int) ([]byte, error)
Encode generates a PNG byte slice representing the QR code for the given content, recovery level, and size.
func NewGFPolyOperator ¶
func NewGFPolyOperator() polyOperator
NewGFPolyOperator creates and returns a new polyOperator instance.
func WriteColorFile ¶
func WriteColorFile( content string, level RecoveryLevel, size int, background, foreground color.Color, filename string, ) error
WriteColorFile generates a QR code with custom background and foreground colors and writes it to a file.
Types ¶
type Bit ¶
type Bit bool
Bit represents a single bit mapped to a boolean value.
func (Bit) Representation ¶
Representation returns the rune representation of the bit ('1' for true, '0' for false).
type Bitset ¶
type Bitset struct {
// contains filtered or unexported fields
}
Bitset represents a set of bits backed by a byte array.
func NewFromBase2String ¶
NewFromBase2String creates a new Bitset from a base-2 string representation (e.g., "1010"). It ignores space characters and panics if an invalid character is encountered.
func (*Bitset) AppendBits ¶
AppendBits appends a sequence of Bit values to the Bitset.
func (*Bitset) AppendBools ¶
AppendBools appends a sequence of boolean values to the Bitset.
func (*Bitset) AppendByte ¶
AppendByte appends a specified number of bits from a byte to the Bitset. It panics if numBits is greater than 8.
func (*Bitset) AppendBytes ¶
AppendBytes appends all the bits from the provided byte slice to the Bitset.
func (*Bitset) AppendNumBools ¶
AppendNumBools appends a specific boolean value a given number of times to the Bitset.
func (*Bitset) AppendUint32 ¶
AppendUint32 appends a specified number of bits from a uint32 value to the Bitset. It panics if numBits is greater than 32.
func (*Bitset) At ¶
At returns the boolean value of the bit at the specified index. It panics if the index is out of bounds.
func (*Bitset) ByteAt ¶
ByteAt constructs and returns a byte from up to 8 bits starting at the specified index. It panics if the index is out of bounds.
func (*Bitset) Equals ¶
Equals returns true if the current Bitset and the other Bitset are equal in length and content.
type QRCode ¶
type QRCode struct {
Content string
Level RecoveryLevel
VersionNumber int
ForegroundColor color.Color
BackgroundColor color.Color
DisableBorder bool
// contains filtered or unexported fields
}
QRCode represents a generated QR code with its content, configuration, and structural data.
func NewQRCode ¶
func NewQRCode(content string, level RecoveryLevel) (*QRCode, error)
NewQRCode creates a new QRCode with the given content and error recovery level. It automatically determines the smallest possible QR code version that can fit the content.
func NewWithForcedVersion ¶
func NewWithForcedVersion(content string, version int, level RecoveryLevel) (*QRCode, error)
NewWithForcedVersion creates a new QRCode using a specific version and error recovery level. It returns an error if the content exceeds the capacity of the specified version.
func (*QRCode) Bitmap ¶
Bitmap returns a 2D boolean array representing the QR code's modules. True represents a foreground module, and false represents a background module.
func (*QRCode) Image ¶
Image returns an image.Image representation of the QR code mapped to the specified pixel size.
func (*QRCode) ToSmallString ¶
ToSmallString returns a more compact string representation of the QR code using half-block characters. It is ideal for terminals with limited vertical space.
func (*QRCode) ToString ¶
ToString returns a string representation of the QR code using unicode block characters. It is useful for printing the QR code to a standard terminal.
func (*QRCode) WithColors ¶
WithColors sets custom foreground and background colors for the QR code. It returns the modified QRCode instance for chaining.
func (*QRCode) WithNoBorder ¶
WithNoBorder disables the quiet zone (border) around the QR code. It returns the modified QRCode instance for chaining.
func (*QRCode) Write ¶
Write encodes the QR code as a PNG of the given size and writes it to the provided io.Writer.
func (*QRCode) WriteFile ¶
WriteFile writes the QR code as a PNG to a file with the specified size and filename.
func (*QRCode) WriteFileWithoutSize ¶
WriteFileWithoutSize writes the QR code to a file using the DefaultFileSize.