Simple no-dependency QR code library.
- Go 100%
Split data into optimal segments (numeric, alphanumeric, byte) using greedy segmentation with merge heuristics from QR spec Annex J. This encodes alphanumeric runs at 5.5 bits/char instead of 8, enabling smaller QR versions for data like TOTP URIs with base32 secrets. |
||
|---|---|---|
| decode.go | ||
| encode.go | ||
| go.mod | ||
| mask.go | ||
| micro.go | ||
| mode.go | ||
| placement.go | ||
| png.go | ||
| qr.go | ||
| qr_test.go | ||
| readme.md | ||
| rs.go | ||
| svg.go | ||
| tables.go | ||
qr
A zero-dependency Go library for generating QR codes and Micro QR codes.
Install
go get git.sharkk.net/go/qr
Usage
SVG
svg, err := qr.SVG("https://example.com", 256)
PNG
data, err := qr.PNG("https://example.com", 256)
Encode with options
code, err := qr.Encode("https://example.com", qr.WithECC(qr.M), qr.WithVersion(3))
svg := code.SVG(256)
png, err := code.PNG(256)
Micro QR
Micro QR codes are smaller and suited for short data. Force a version directly or let the encoder pick the smallest one:
// Force a specific Micro QR version
code, err := qr.Encode("12345", qr.WithVersion(qr.VersionM1))
// Auto-select (tries M1–M4 first, then standard 1–10)
code, err := qr.Encode("12345", qr.WithMicro(true))
Micro QR version capabilities:
| Version | Size | Modes | ECC Levels |
|---|---|---|---|
| M1 | 11×11 | Numeric | L |
| M2 | 13×13 | Numeric, Alphanum | L, M |
| M3 | 15×15 | Numeric, Alphanum, Byte | L, M |
| M4 | 17×17 | Numeric, Alphanum, Byte | L, M, Q |
Options
| Option | Description |
|---|---|
WithECC(level) |
Error correction level: L (default), M, Q, H |
WithVersion(v) |
Force QR version: 1–10 standard, VersionM1–VersionM4 micro |
WithMicro(true) |
Prefer Micro QR during auto version selection |
Output
SVG output uses a single <path> element for compact rendering. The module
grid is also available directly via Code.Modules for custom renderers.