QRex is a high-performance QR code detection and decoding library for Elixir, powered by Rust NIFs.
- Fast QR code detection and decoding
- Support for multiple QR codes in a single image
- Pre-compiled NIFs for major platforms
- Simple, straightforward API
- Detailed error reporting
Add qrex
to your list of dependencies in mix.exs
:
def deps do
[
{:qrex, "~> 0.1.0"}
]
end
# Read an image file
image_bytes = File.read!("path/to/image.png")
# Detect and decode QR codes
case QRex.detect_qr_codes(image_bytes) do
{:ok, results} ->
# Process each detected QR code
Enum.each(results, fn
{:ok, qr_code} ->
IO.puts "Found QR code: #{qr_code.text}"
IO.puts "Version: #{qr_code.version}"
IO.puts "Bounds: #{inspect(qr_code.bounds)}"
{:error, reason} ->
IO.puts "Failed to decode QR code: #{reason}"
end)
{:error, reason} ->
IO.puts "Failed to process image: #{reason}"
end
The decoded QR code struct (QRex.QRCode
) contains:
text
- The decoded contentversion
- QR code version (1-40)modules
- Size in modules (21-177)ecc_level
- Error correction level (0-3)bounds
- Corner coordinates as[{x, y}, ...]
QRex provides pre-compiled NIFs for:
- Linux (x86_64, aarch64)
- macOS (x86_64, arm64)
- Windows (x86_64)
For other platforms, the library will attempt to compile from source. You'll need:
- Rust toolchain (1.79.0 or later)
- C compiler
- Development headers
To force building from source, set the environment variable:
export RUSTLER_PRECOMPILATION_QREX_BUILD=1
mix deps.compile qrex --force
QRex is designed for high performance, leveraging Rust's speed and safety features:
- Fast image processing algorithms
- Zero-copy data handling where possible
- Efficient memory management
Licensed under:
- MIT license (LICENSE)