qrcode
stableGenerates QR codes from text, producing SVG strings, ASCII art, raw module data, or metadata about the encoded content.
use plugin qrcode Plugin snippets can be edited in the Playground, but native capabilities are executed locally with the Zolo CLI.
Functions (7)
- generate Generate QR code as raw module data
- generate_svg Generate QR code as an SVG string
- generate_svg_sized Generate SVG at a specific pixel size
- to_string Render QR code as Unicode block art
- generate_with_ec Generate with explicit error correction level
- encode_info Get QR metadata without full module data
- version_for_length Find minimum QR version for a text length
From import to result
- 01Import only what you use
- 02Copy the smallest example
- 03Run it with the Zolo CLI
Overview¶
qrcode turns any text into a QR code without external tooling. It is stateless
and handle-free: every function takes a plain string and returns a ready-to-use
value, so there is no encoder object to construct or dispose. You choose the
output that fits the destination — a self-contained SVG document for the web,
Unicode block art for the terminal, a flat boolean module grid for custom
rendering, or a small metadata table when you only need facts about the code.
The core concept is the module grid: a square of size × size cells where each
cell is either dark (true) or light (false), stored row-major in a flat table.
SVG and ASCII renderers walk that same grid for you, while generate and
generate_with_ec hand it back so you can draw it yourself. Error correction
level ("L", "M", "Q", "H") trades capacity for resilience; "M" is the
default everywhere it is optional.
Common patterns¶
Render a scannable QR code straight to the terminal:
use plugin qrcode::{to_string}
print(to_string("https://zolo-lang.dev"))Produce a fixed-size SVG and report what the encoder picked for it:
use plugin qrcode::{generate_svg_sized, encode_info}
let url = "https://zolo-lang.dev/docs"
let svg = generate_svg_sized(url, 256)
let info = encode_info(url)
print("version {info["version"]}, {info["size"]}x{info["size"]} modules")
print(svg)Plan capacity, then draw the raw grid by hand:
use plugin qrcode::{version_for_length, generate}
let payload = "ORDER-2026-000457"
print("fits in version {version_for_length(payload.len())}")
let qr = generate(payload)
let n = qr["size"]
for y in 0..n {
let mut line = ""
for x in 0..n {
line = line + (if qr["modules"][y * n + x] { "##" } else { " " })
}
print(line)
}Generate QR code as raw module data
Encodes the text and returns #{size: int, modules: table}. modules is a flat boolean table (row-major) where true means a dark module. size is the width/height in modules.
use plugin qrcode::{generate}
let qr = generate("https://zolo-lang.dev")
print("QR size: {qr["size"]}x{qr["size"]}")Walk the flat module table to count dark cells:
use plugin qrcode::{generate}
let qr = generate("PING")
let n = qr["size"]
let dark = 0
for i in 0..(n * n) {
if qr["modules"][i] {
dark = dark + 1
}
}
print("{dark} dark modules of {n * n}")Generate QR code as an SVG string
Generates a complete SVG document for the QR code. Includes a 4-module quiet zone margin. Each dark module is a 1-unit <rect>.
use plugin qrcode::{generate_svg}
let svg = generate_svg("Hello, World!")
// write svg to a file or embed in HTML
print(svg)Generate SVG at a specific pixel size
Like generate_svg but scales the output to exactly px_size pixels square. Useful when you need a specific canvas dimension.
use plugin qrcode::{generate_svg_sized}
let svg = generate_svg_sized("https://example.com", 256)
print(svg)Render QR code as Unicode block art
Renders the QR code as Unicode block characters using half-block glyphs, producing a compact terminal-friendly representation. ec_level is optional: "L", "M" (default), "Q", or "H".
use plugin qrcode::{to_string}
print(to_string("scan me"))
print(to_string("high reliability", "H"))Because two module rows are packed into each text line with half-block glyphs, the printout is roughly half as tall as the module grid — handy for logging a code that still scans from the screen:
use plugin qrcode::{to_string}
let art = to_string("wifi:guest")
print(art)Generate with explicit error correction level
Like generate but lets you choose the error correction level. Returns #{size, modules, version, ec_level}. EC levels: "L" (7%), "M" (15%), "Q" (25%), "H" (30%).
use plugin qrcode::{generate_with_ec}
let qr = generate_with_ec("product:12345", "Q")
print("version {qr["version"]}, size {qr["size"]}")Higher correction levels resist damage but grow the code; compare the size that the same payload needs at the two extremes:
use plugin qrcode::{generate_with_ec}
let low = generate_with_ec("label", "L")
let high = generate_with_ec("label", "H")
print("L -> {low["size"]} modules, H -> {high["size"]} modules")Get QR metadata without full module data
Returns metadata about the QR code without generating full module data. Faster when you only need #{version, size, ec_level, data_bytes}.
use plugin qrcode::{encode_info}
let info = encode_info("https://zolo-lang.dev/docs")
print("QR version {info["version"]}, {info["data_bytes"]} data bytes")Find minimum QR version for a text length
Returns the minimum QR version (1–40) capable of encoding len alphanumeric characters at error correction level M. Useful for capacity planning.
use plugin qrcode::{version_for_length}
let url = "https://example.com/very/long/path"
let v = version_for_length(url.len())
print("need at least QR version {v}")