data_matrix

Library that enables programs to write Data Matrix barcodes of the modern ECC200 variety.


Keywords
cli, code, data, data-matrix, datamatrix, ecc, ecc200, elixir, generator, matrix
License
MIT

Documentation

Data Matrix · GitHub license Downloads

This is a software library that enables programs to write Data Matrix barcodes of the modern ECC200 variety.

  • Supports rectangular symbols (this is optional according to ISO/IEC 16022:2006(E))

References:

  • ISO/IEC 16022:2006(E)

Table of Contents

Installation

The package can be installed by adding data_matrix to your list of dependencies in mix.exs:

def deps do
  [
    {:data_matrix, "~> 0.1.2"}
  ]
end

To find out the latest release available on Hex, you can run mix hex.info datamatrix in your shell, or by going to the datamatrix page on Hex.pm

Then, update your dependencies:

mix do deps.get, deps.compile

CLI

You can create Data Matrix symbols using the command line as follows:

  1. Install datamatrix as an escript:
mix escript.install github 0x8b/datamatrix
  1. Then you are ready to use it:
datamatrix -i "input.txt"          # or

datamatrix input_text              # or

cat input_text.txt | datamatrix -  # read standard input

For more details about using the command line tool, review the usage guide:

datamatrix --help

Examples

Note: DataMatrix.encode returns {:ok, symbol} or {:error, reason}

data = "hello"

{:ok, symbol} =
  data
  |> DataMatrix.encode(shape: :rectangle)

png =
  symbol
  |> DataMatrix.format(:png, module_size: 8)

File.write("symbol.png", png)

Example rectangular Data Matrix

{:ok, symbol} = DataMatrix.encode("123456", quiet_zone: 4)

svg = DataMatrix.format(symbol, :svg, light: "#ffff00", width: 200)

File.write!("square.svg", svg)

Example square Data Matrix

Encoding parameters

ArgumentError is thrown when the number of data codewords exceeds the symbol capacity.

Parameter Default value Description
quiet_zone 1 All four sides of symbol are surrounded by quiet zone border.
version auto See Maximum data capacity. Version is selected automatically if not specified.
shape :square Shape of symbol. Available shapes are :square and :rectangle.

Rendering parameters

Available output formats:

PNG parameters

Parameter name Default value Description
module_size 10 Size of module.
dark "#000000" Color of dark module. Only #RRGGBB
light "#ffffff" Color of light module. Only #RRGGBB

SVG parameters

Parameter name Default value Description
width auto Width in pixels (quiet zone included).
height auto Height in pixels (quiet zone included).
viewbox false Width and height are not included in SVG if viewbox is set to true.
module_size 5 Size of module.
dark "black" Color of dark module. Color syntax for SVG w3.org 🡕
light "white" Color of light module.

Note:

Text parameters

Parameter name Default value Description
dark "1" Representation of dark module.
light "0" Representation of light module.
separator "" String that is used to join modules in a row.
newline "\n" String that is used to join rows.

Maximum data capacity

See docs/maximum_data_capacity.md

Notes

All additional features mentioned below will be provided in next major releases.

ECC 200 includes various encodation schemes which allow a defined set of characters to be converted into codewords more efficiently than the default scheme.

Extended Channel Interpretations mechanism enables characters from other character sets (e.g. Arabic, Cyrillic, Greek, Hebrew) and other data interpretations or industry-specific requirements to be represented.

Structured append allows files of data to be represented in up to 16 Data Matrix symbols. The original data can be correctly reconstructed regardless of the order in which the symbols are scanned.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to:

  • update tests as appropriate
  • run mix format

Contact

If you want to contact me you can reach me at mkgumienny@gmail.com

License

MIT