| Crates.io | zedbar |
| lib.rs | zedbar |
| version | 0.1.0 |
| created_at | 2025-11-07 15:36:32.580608+00 |
| updated_at | 2025-11-07 15:36:32.580608+00 |
| description | Pure Rust barcode and QR code scanning library supporting multiple formats |
| homepage | |
| repository | https://github.com/eventualbuddha/zbar |
| max_upload_size | |
| id | 1921741 |
| size | 3,689,425 |
A pure Rust implementation of barcode scanning, based on the ZBar bar code reader C library.
This is a port of the ZBar library to Rust, providing barcode detection and decoding capabilities with a type-safe, idiomatic Rust API.
zedbarimg utility for scanning images from the command lineAdd to your Cargo.toml:
[dependencies]
zedbar = "0.1"
By default, all symbologies are enabled. You can selectively enable only the ones you need to reduce compile time and binary size:
[dependencies]
zedbar = { version = "0.1", default-features = false, features = ["qrcode", "ean"] }
qrcode - QR Code 2D barcodesqcode - SQ Code 2D barcodeean - EAN-8, EAN-13, UPC-A, UPC-E, ISBN-10, ISBN-13code128 - Code 128code39 - Code 39code93 - Code 93codabar - Codabardatabar - GS1 DataBar (RSS)i25 - Interleaved 2 of 5Heavy dependencies (tied to features):
encoding_rs, reed-solomon, rand, rand_chacha - Required for QR code decoding (enabled with qrcode feature)image - Image format loading (PNG, JPEG, etc.) - needed for tests and the zedbarimg binaryclap - Command-line parsing (needed for the zedbarimg binary)Note: 1D barcode decoders (EAN, Code39, Code128, etc.) have zero external dependencies!
The default feature enables all symbologies plus optional dependencies:
default = ["qrcode", "sqcode", "ean", "code128", "code39", "code93", "codabar", "databar", "i25", "image", "clap"]
For the absolute minimal build with zero external dependencies (1D barcodes only):
[dependencies]
zedbar = { version = "0.1", default-features = false, features = ["ean"] }
For QR codes only (with necessary dependencies):
[dependencies]
zedbar = { version = "0.1", default-features = false, features = ["qrcode"] }
Note: Disabling a feature at compile-time means that symbology will not be compiled into the binary at all, which is different from disabling it via runtime configuration.
use zedbar::{Image, Scanner};
// Load and convert image to grayscale
let img = image::open("barcode.png")?;
let gray = img.to_luma8();
let (width, height) = gray.dimensions();
// Create scanner and scan image
let mut img = Image::from_gray(gray.as_raw(), width, height)?;
let mut scanner = Scanner::new();
let symbols = scanner.scan(&mut img);
// Process decoded symbols
for symbol in symbols {
println!("{:?}: {}", symbol.symbol_type(), symbol.data_string().unwrap_or(""));
}
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);
# Build the tool
cargo build --release --bin zedbarimg
# Scan an image
cargo run --bin zedbarimg examples/test-qr.png
cargo run --bin zedbarimg examples/test-ean13.png
cargo test
Comprehensive benchmarks comparing this library with rqrr, rxing, and the original C zbar library are available:
# Compare with rqrr (default)
cargo bench
# Compare with all libraries (requires optional dependencies)
cargo bench --features bench_zbar_c,bench_rxing
See benches/README.md for detailed benchmark documentation and results.
This project is based on the ZBar bar code reader library:
The original ZBar library is licensed under LGPL 2.1 or later.
This Rust implementation preserves the algorithms and structure of the original C library while providing a safe, idiomatic Rust API.
If this library doesn't meet your needs, consider these alternatives:
rqrr - it's fast, pure Rust, and has a simpler API.zedbar) or rxing.zbar-rust which provides FFI bindings to the original C library.LGPL 3.0 or later - See LICENSE for details.
This library is licensed under the GNU Lesser General Public License v3.0 or later, consistent with the original ZBar library's licensing.