The QRCODE Image Format

A Collection of Interesting Ideas,

This version:
https://tabatkins.github.io/specs/qrcode/
Issue Tracking:
GitHub
Editor:
Tab Atkins-Bittner

Abstract

The "QR Code", invented in the 1990s, has emerged in recent years as the clear winner of the "encode small but complex data, especially URLs, for phones to read" format wars. All phone OSes have built-in ways to read them, and to generate them, but that generation capability isn’t exposed to websites.

This specification defines a new image type, image/qrcode, which represents the data in a QR code in a declarative, compact manner which is easily readable and hand-writable. Browser and other rendering agents that understand this format are expected to automatically generate a QR code image representing the data in the resource.

1. Introduction

Representing relatively small amounts of data in a machine-readable format has been important for decades. The humble UPC barcode format, for instance, allows storing numeric values up to ten decimal digits.

As time has passed, tho, we’ve required larger amounts of data to be represented (even if the amounts are still modest; a few kilobytes at most), and better error correction (UPC barcodes can correct for one wrong digit, but no more). Many approaches have been proposed and even adopted in various industries, but the QR Code, first invented in Japan in the 90s for labeling parts in semi-automated factories, has emerged as the clear leader in overall usage across the world in recent years.

While QR Code images are very usable in practice, they’re difficult to create; beyond the ordinary difficulties of creating any image file programmatically, the QR format is non-trivial to follow, and the error-correction parts of the format are complex. However, all the devices a user can expect to see a QR Code have access to libraries for creating them.

This specification defines a new QRCODE image format, and its associated MIME type image/qrcode, which represents the content of a QR code in a simple, human-readable, hand-authorable format. User agents, such as browsers, that recieve QRCODE images are expected to render them as QR codes.

2. Notes

Parameters of a QR code:

Additional params I need to introduce:

3. Image Format

Every QRCODE image must begin with the bytes 51 52 43 4f 44 45 7b (spelling "QRCODE{" in ASCII). Following that are zero or more non-7d bytes (the parameter bytes), followed by a 7d byte ("}" in ASCII), optionally followed by 0d 0a bytes (CR and NL in ASCII), followed by zero or more bytes with any value (the payload bytes).

A QRCODE image that does not follow this byte format is invalid.

Thus, a valid QRCODE file might be QRCODE{}https://example.com, which will be rendered as QR Code image containing a link to example.com.

Alternately, the link could be rendered on a separate line for readability, like:

QRCODE{}
https://example.com

This is particular useful if several parameters are provided, like:

QRCODE{version=5;error=low;mask=3;modulesize=5;margin=2}
https://example.com

3.1. Parameters

The parameter bytes are interpreted into the QR code parameters, which affect how the QR code image is generated. The format is intentionally identical to how MIME-type parameters are interpreted.

To parse parameter bytes bytes execute the following steps. It returns either QR code parameters, or failure.
  1. Let str be the result of isomorphic decoding bytes. Let parameters be an empty QR code parameters.

  2. Strictly split str on the delimiter U+003B SEMICOLON (;), and let param strings be the result.

  3. For each param string of param strings:

Conformance

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-SYNTAX-3]
Tab Atkins Jr.; Simon Sapin. CSS Syntax Module Level 3. URL: https://drafts.csswg.org/css-syntax/
[INFRA]
Anne van Kesteren; Domenic Denicola. Infra Standard. Living Standard. URL: https://infra.spec.whatwg.org/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119