# Qr.Encode

> 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.

<!-- id: function-qr-encode · area: function · stability: stable · html: https://osysharp.com/reference/function/qr-encode/ -->

## Summary        {#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      {#signature}
```osy syntax
Qr.Encode(<string> text) -> List<string>
```

## Description    {#description}

### What it makes        {#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        {#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        {#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       {#examples}
```osy title="a code a page can draw" test app=qr-encode
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       {#see-also}
- [publishing a REST API (app.Apis)](https://osysharp.com/reference/api/rest/) — `Request.ClientAddress`, the other half of a BankID flow the server runs
- [Text.Split](https://osysharp.com/reference/function/text-split/) — other in-memory string builtins
