Osy#betaRun it on Osyrin: osyrin.com

Reference / Function

Qr.Encode

Qr.Encode(text) → List<string> (one row of modules per string, top to bottom, '1' dark)

A QR code for a piece of text, as rows of modules a page draws with ordinary boxes — level M, the smallest version that holds it, the mask the standard prefers. Server-side and fast enough to redraw every second, which is what a code that changes every second (BankID's animated QR) needs.

stable1 example compiled by CIfunctionstdlibui

Summary#

Qr.Encode(text) returns a QR code for text as a List<string>: one string per row, top to bottom, each character a module — '1' dark, '0' light. Every row is as long as the list, so a code is rows.Count modules a side.

Signature#

Qr.Encode(<string> text) -> List<string>

Description#

What it makes#

Byte mode (the text as UTF-8), error correction level M (about 15 % of the code may be damaged and still read), in the smallest version that holds the text, with the mask the standard's penalty scores best. Text too long for any version (over 2,328 bytes) is refused with the limit in the message.

Drawing it#

Draw the modules dark on light whatever the page's colours, with a light margin of four modules on every side — a reader looks for three dark finder squares on a light ground, and a code drawn light-on-dark or cropped tight reads on nothing. A row is cheapest to draw as its runs: a Row of boxes, one per stretch of the same colour.

Why it runs on the server#

The text a code carries is usually made on the server — a provider's frame derived from a secret the browser must never hold, like BankID's animated QR, which changes every second. So the encoder is native to the server, and the page is sent the rows. It is fast enough to redraw every second for every viewer.

Examples#

class Code { public List<string> Rows = []; public int Side; }

Code ForScanning(string text) {
  var rows = Qr.Encode(text);
  return new Code { Rows = rows, Side = rows.Count };
}
// ForScanning("HELLO WORLD").Side  ->  21  (version 1)

See also#

Related

publishing a REST API (app.Apis)

`app.Apis` publishes your app to a third party over HTTP. You never write a controller or an endpoint handler — you…

Text.Split

The C# string.Split: breaks a string on a separator and returns the substrings as a List<string> — iterable with…