{qr}
Draws a QR code as inline SVG, encoded on the server - no image library, no remote service.
Syntax
{qr 'text'}
{qr $url, size=160, level='M', title='text', color='#000', background='#fff'}
Parameters
-
text - The text to encode - an address, a payment or Wi-Fi string, anything up to 2,953 bytes at level L.
Options
-
size - Width and height in pixels, the quiet zone of four modules included; default 160, at least 21.
-
level -
Error correction:
L(7% of the symbol may be lost),M(15%, default),Q(25%) orH(30%). -
title - The accessible name, by default the text itself.
-
color -
The dark colour, default
#000. -
background -
The light colour, default
#fff.
Description
{qr} encodes its first parameter as a QR code and writes it as an inline SVG. The encoder is PAD's own (tags/_lib/qr.php): nothing is fetched and no image is stored, and the same text is always the same picture, so a page with a code caches and prints like any other.
The text is encoded in one mode - numeric for digits only, alphanumeric for upper case, digits and $%*+-./:, else the bytes of its UTF-8 - in the smallest of the 40 versions that holds it at the error correction asked, under the mask with the lowest penalty. A higher level survives more damage (a logo printed over it, a scratched label) at the cost of a denser code.
The colours are fixed, #000 on #fff unless color and background say otherwise - not following the page's dark mode, since a reader needs the contrast and a light quiet zone. The SVG has role="img" and the text (or title) as its name.
A text too long for version 40 at the level asked, or a level other than L, M, Q or H, is an error under the strict check, and the tag writes nothing. For a one-dimensional code on a product or a parcel see {barcode}.
Examples
An address
The text is the first parameter; the default is 160 pixels at level M.
{qr 'https://example.com/order/42'}
Level, size and colours
Level H survives the most damage; a dark colour other than black keeps the contrast.
{qr 'WIFI:T:WPA;S:Office;P:correct-horse;;', size=200, level='H', color='#1b5e20', title='Join the office Wi-Fi'}