Library
Module
Module type
Parameter
Class
Class type
QR code encoder.
Consult the limitations and an encoding example.
References.
ISO/IEC 18004:2015. QR Code bar code symbology specification.
module Matrix : sig ... end
QR 2D matrices.
The type for QR code error correction levels. Four levels respectively allowing 7%, 15%, 25% and 30% recovery of the QR code.
module Gf_256 : sig ... end
Arithmetic over galois field GF(28).
module Prop : sig ... end
QR code properties.
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
.
`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.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)