package qrc

  1. Overview
  2. Docs

QR code encoder.

Consult the limitations and the quick start.

References.

ISO/IEC 18004:2015. QR Code bar code symbology specification.

Matrices

module Matrix : sig ... end

QR 2D matrices.

Properties

type version = [
  1. | `V of int
]

The type for QR code versions, from 1 to 40.

type ec_level = [
  1. | `L
    (*

    7%

    *)
  2. | `M
    (*

    15%

    *)
  3. | `Q
    (*

    25%

    *)
  4. | `H
    (*

    30%

    *)
]

The type for QR code error correction levels. Four levels respectively allowing 7%, 15%, 25% and 30% recovery of the QR code.

type mode = [
  1. | `Byte
    (*

    byte data

    *)
]

The type for (supported) data encoding modes.

module Gf_256 : sig ... end

Arithmetic over galois field GF(28).

module Prop : sig ... end

QR code properties.

Encoding

val encode : ?mask:int -> ?version:version -> ?mode:mode -> ?ec_level:ec_level -> string -> Matrix.t option

encode ~version ~mode ~ec_level data is a QR matrix encoding bytes data with:

  • ec_level, the error correction level, defaults to `M.
  • version, the version of the QR code. If unspecified the minimal needed version for the given ec_level is used.
  • mode is the encoding mode. If unspecified it is guessed, but guess what, only `Byte mode is supported.
  • mask can be used to force the data mask. This should not be used, the best mask to please your scanner is automatically selected as mandated by the standard.

None is returned if data is too large to be fit the specified QR code parameters. Use Prop.mode_capacity to find data capacity for given QR code properties beforehand.

Note. Sometimes once the version and ec_level constraints are satisfied for data we can fit the data in a higher ec_level with the same version (i.e. same matrix width). In that case that higher error correction level is used instead of the given or default ec_level.

Notes and limitations

Encoding

  • Only the (universal) byte mode data encoding is supported. This may mean larger QR codes if you are trying to encode only decimal digits, only decimal digits and uppercase US-ASCII letters or only Kanji characters.
  • For textual data, using UTF-8 with `Bytes should work reasonably well. The module does not implement the ECI scheme to specify the encoding. Signals from the interwebs seem to indicate it's better to let scanners auto-discover the encoding as some do not understand the ECI scheme.
  • Structured append, i.e. data represented by up to 16 linked QR codes, is not supported – who does ?
OCaml

Innovation. Community. Security.