A square QR code, read with a phone
Draw a QR code carrying a web address or a piece of text, read by any phone, with its white margin all around.
Summary
The little square of black dots you point a phone camera at. A web address, an order number, a network password: whatever it carries, the square is drawn at the size the frame allows, with the small white margin that lets a phone recognise it first time. The longer the text, the finer the dots — so for a code read from a distance, or printed small, a short text works best. You may also ask for a sturdier code, one that still reads when it is scuffed or torn: it holds the same text in a slightly larger square.
Technically
Asked for with
"type": "qr"
How much of the code is kept back to bring it home when it is damaged, and how the code spells what it carries, are both stated rather than guessed at. Absent, the text is spelled byte by byte, which covers ASCII as well as UTF-8, and about fifteen parts in a hundred are kept back — what the code was drawn at before either key existed. A text the stated spelling cannot hold is refused rather than carried another way. The modules are drawn as filled squares in the page content stream. The square and its quiet zone on all four sides fill the rectangle's width, and the whole is anchored at the lower-left corner: the rectangle's height is headroom, its width commands. The version chosen is the smallest that holds the text as spelled and at the error correction level asked for, 21×21 up to 177×177; beyond the largest symbol the answer is 400. As with the other codes, the item draws the symbol alone, and the human-readable text is laid beside it.
Request schema
Required keys: content, a non-empty string; rect. Optional: correction, one of low, medium (default), quartile or high, how much of the code is kept back to bring it home when it is damaged; mode, one of numeric, alphanumeric or byte (default), how the code spells what it carries; pages, an array of one-based integers, default empty; transform, six numbers; rotate, degrees counter-clockwise about the centre of the rectangle; layer, the name of a declared layer. Cross refusal: transform together with rotate. A text the stated mode cannot spell answers 400, and so does one longer than the largest symbol carries at the error correction level asked for.
A whole request that creates a PDF
{
"items": [
{
"type": "qr",
"content": "https://hqf-pdf.com/",
"correction": "quartile",
"mode": "byte",
"rect": {"llx": 72, "lly": 680, "urx": 152, "ury": 760}
}
]
}
Barcodes and square codes
A barcode of vertical bars An Aztec code, with no white margin around it A Data Matrix code, very small and very sturdy A PDF417 code, carrying a whole form
Where to go next
Every JSON key of a request, in one page The other twenty-two things you can draw