Module QrcSource

QR code encoder.

Consult the limitations and an encoding example.

References.

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

Matrices

Sourcemodule Matrix : sig ... end

QR 2D matrices.

Properties

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

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

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

Sourcetype mode = [
  1. | `Byte
    (*

    byte data

    *)
]

The type for (supported) data encoding modes.

Sourcemodule Gf_256 : sig ... end

Arithmetic over galois field GF(28).

Sourcemodule Prop : sig ... end

QR code properties.

Encoding

Sourceval 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

Example

The following generates a QR code matrix for the given data bytes and outputs it as an SVG image on stdout.

  let output_svg_qr data = match Qrc.encode data with
  | None -> prerr_endline "Data capacity exceeded!"
  | Some m -> print_endline (Qrc.Matrix.to_svg m)