Documentation
¶
Overview ¶
Package qr generates QR Code symbols per ISO/IEC 18004 using only the Go standard library. It supports numeric, alphanumeric and byte modes, all 40 versions and all four error-correction levels, with automatic mode and version selection and automatic mask selection.
Kanji mode and ECI are intentionally not implemented; byte-mode content is emitted as its raw bytes (UTF-8 for Go strings), which every modern decoder interprets correctly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoded ¶
type Decoded struct {
Version int
Level Level
Mask int
Mode string // "numeric", "alphanumeric" or "byte"
Text string
Errors int // number of codeword errors corrected
}
Decoded is the result of decoding a symbol.
func DecodeMatrix ¶
DecodeMatrix decodes a module matrix (true = dark), performing format recovery, unmasking, de-interleaving and Reed-Solomon error correction.
It complements the encoder and is used for in-repo round-trip verification; it also decodes matrices produced by other conforming encoders.
func DecodePNG ¶
DecodePNG decodes a QR symbol from a clean, high-contrast, axis-aligned image (PNG, JPEG or GIF — a render, screenshot, or flat scan). It is not a perspective-correcting photo decoder: it assumes the symbol is upright, unrotated and rendered with square modules on a light quiet zone.
The input is treated as untrusted: encoded size is capped at 32 MiB and declared dimensions at 32768x32768 before any pixel buffer is allocated.
type Level ¶
type Level int
Level is the error-correction level. The values are ordered by recovery capacity and are used directly as indices into the parameter tables.
type QRCode ¶
type QRCode struct {
Version int
Level Level
Size int // modules per side
// contains filtered or unexported fields
}
QRCode is a finished symbol.
func Encode ¶
Encode builds the smallest symbol that holds content at the given level, selecting mode, version and mask automatically.
func EncodeVersion ¶
EncodeVersion builds a symbol at a fixed version (1..40), returning an error if content does not fit.
func (*QRCode) Decode ¶
Decode decodes this symbol back to its content, applying Reed-Solomon error correction. It is primarily a self-check: Encode followed by Decode must round-trip.
func (*QRCode) Matrix ¶
Matrix returns the module grid as rows of booleans (true = dark). The result is a fresh copy the caller may modify.
func (*QRCode) Module ¶
Module reports whether the module at (x, y) is dark. x is the column and y the row, both zero-based from the top-left. Out-of-range coordinates return false.
func (*QRCode) PNG ¶
PNG writes the symbol as a PNG. moduleSize is the pixel width of one module (>=1) and border is the quiet-zone width in modules (the standard minimum is 4). The rendered side length is capped at 32768 pixels.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
qrgen
command
Command qrgen writes a QR Code PNG (or ASCII) for the given text.
|
Command qrgen writes a QR Code PNG (or ASCII) for the given text. |
|
example
|
|
|
http
command
Command http is a minimal example: serve QR codes over HTTP.
|
Command http is a minimal example: serve QR codes over HTTP. |
|
mcp
command
Command mcp is a minimal example: expose the QR encoder to an AI agent over the Model Context Protocol.
|
Command mcp is a minimal example: expose the QR encoder to an AI agent over the Model Context Protocol. |
|
unix
command
Command unix is a minimal example: serve QR codes over a Unix-domain socket — a local sidecar reachable only from the same host, with filesystem permissions as the access control.
|
Command unix is a minimal example: serve QR codes over a Unix-domain socket — a local sidecar reachable only from the same host, with filesystem permissions as the access control. |