Skip to main content

Crate zedbar

Crate zedbar 

Source
Expand description

Zedbar Barcode Scanning Library

A pure Rust barcode scanning library supporting multiple barcode formats including QR codes, EAN, UPC, Code128, Code39, and more. Based on the ZBar C library.

§Quick Start

use zedbar::{Image, Scanner};

// Load and convert image to grayscale
let img = image::open("barcode.png").unwrap();
let gray = img.to_luma8();
let (width, height) = gray.dimensions();

// Create image and scanner
let mut img = Image::from_gray(gray.as_raw(), width, height).unwrap();
let mut scanner = Scanner::new();

// Scan for barcodes
let symbols = scanner.scan(&mut img);
for symbol in symbols {
    println!("{:?}: {}", symbol.symbol_type(), symbol.data_string().unwrap_or(""));
}

§Configuration

Use the type-safe config module to customize decoder behavior:

use zedbar::config::*;
use zedbar::{DecoderConfig, Scanner};

let config = DecoderConfig::new()
    .enable(QrCode)
    .enable(Ean13)
    .set_binary(QrCode, true)          // Preserve binary data in QR codes
    .set_length_limits(Code39, 4, 20)  // Code39 must be 4-20 chars
    .test_inverted(true)               // Try inverted image if no symbols found
    .scan_density(2, 2);               // Scan every 2nd line (faster)

let mut scanner = Scanner::with_config(config);

§Supported Formats

  • 2D Codes: QR Code, SQCode
  • Linear Codes: EAN-13, EAN-8, UPC-A, UPC-E, ISBN-10, ISBN-13
  • Code Family: Code 128, Code 93, Code 39, Codabar
  • Industrial: Interleaved 2 of 5, DataBar (RSS)

§Modules

  • scanner - Main scanner API
  • image - Image handling
  • symbol - Decoded barcode symbols
  • config - Type-safe decoder configuration
  • error - Error types

Re-exports§

pub use config::DecoderConfig;
pub use error::Error;
pub use error::Result;
pub use image::Image;
pub use scanner::Scanner;
pub use symbol::Orientation;
pub use symbol::SymbolType;

Modules§

config
Type-safe configuration system for Zedbar decoders
error
Error types and result handling
image
Image handling and format support
scanner
Image scanner for finding barcodes in 2D images
symbol
Decoded barcode symbols and types