AztecEx

Pure Elixir library for encoding and decoding Aztec 2D barcodes per ISO/IEC 24778:2024.

No external dependencies or NIFs -- works everywhere Elixir runs.

Features

Installation

Add aztec_ex to your list of dependencies in mix.exs:

def deps do
  [
    {:aztec_ex, "~> 0.1.0"}
  ]
end

Quick Start

Encode

{:ok, code} = AztecEx.encode("Hello World")
# => %AztecEx.Code{compact: true, layers: 2, size: 19, ...}

Decode

{:ok, data} = AztecEx.decode(code.matrix)
# => "Hello World"

Render as SVG

svg = AztecEx.to_svg(code, module_size: 4, margin: 2)
File.write!("barcode.svg", svg)

Render as text (terminal)

IO.puts(AztecEx.to_text(code))

Options

Encoding

Option Type Default Description
:error_correctionfloat0.23 Minimum error correction ratio
:min_layersinteger Minimum number of data layers
:compactboolean auto Force compact (true) or full-range (false)

SVG Rendering

Option Type Default Description
:module_sizeinteger4 Pixel size of each module
:margininteger1 Quiet zone modules around symbol
:dark_colorstring"#000000" Color for dark modules
:light_colorstring"#FFFFFF" Color for light modules

Text Rendering

Option Type Default Description
:darkstring"██" Character(s) for dark module
:lightstring" " Character(s) for light module
:newlinestring"\n" Line separator

Architecture

AztecEx.encode/2
  ├── HighLevelEncoder   (data → optimal bitstream)
  ├── BitStuffing        (stuff + pad to codeword boundary)
  ├── ReedSolomon.Encoder (generate check codewords)
  └── Encoder            (symbol layout → BitMatrix)

AztecEx.decode/1
  ├── Decoder            (detect finder, read mode/data)
  ├── ReedSolomon.Decoder (error correction)
  ├── BitStuffing        (unstuff)
  └── HighLevelDecoder   (bitstream → bytes)

License

MIT. See LICENSE for details.