QR

Stable

QR codes for short links, as SVG, in Go and in a page's script

Used by ViF

QR code symbols (ISO/IEC 18004) for text of up to 213 bytes, such as a link, drawn as SVG on an optional pale picture. A Go package on the standard library alone, and the same encoder as one script with no dependencies for a page.

  • Byte mode at error correction level M, versions 1 to 10
  • The mask the standard’s penalty rules choose
  • SVG with the quiet zone, the dark modules black on white, over an optional pale picture
  • qr.js mirrors the Go package function for function, and is tested against it

A symbol and its picture

Encode returns the smallest version that holds the text’s bytes as rows of modules; past 213 bytes it returns an error. SVG draws the dark modules as one black path on white, four light modules of quiet zone on each side, so a reader finds dark on light whatever the page’s theme. A picture given with it, SVG in the symbol’s units, is drawn under the dark modules at 30% over the white: its colors show pale in the light modules, never dark enough to be read as dark.

rows, err := qr.Encode("https://lixen.com/vif/lobby/")
doc := qr.SVG(rows, "")       // or qr.SVG(rows, backdrop)

web/qr.js is the same for a page whose policy allows only its own scripts: qr.encode and qr.svg give what Encode and SVG give. The tests hold Encode to symbols another encoder made, under every mask and at both ends of each version’s range, and qr.js to Encode for every length up to one past the limit.

ViF’s lobby on this site shows a game’s link as a code, the ViF mark pale behind it, for a phone held up to the screen, and ViF in a browser shows its own game’s link so from its share button.