# Getting started (laravel-rust-barcode)

> Install the framework-free crate and render a Code 39 symbol as SVG or HTML.

- Package: laravel-rust-barcode (Laravel for Rust, alpha), crates: `laravel-rust-barcode`, `laravel-rust-barcode-core`
- Maintenance: active; Latest release: 0.1.0 (2026-12-05); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-barcode), [crates.io](https://crates.io/crates/laravel-rust-barcode/0.1.0), [docs.rs](https://docs.rs/laravel-rust-barcode/0.1.0), [Changelog](https://oss.bowerbird.si/barcode/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-barcode/blob/3cc853b5abd7af2bf6028407dda457fb69bdf231/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-barcode/blob/3cc853b5abd7af2bf6028407dda457fb69bdf231/SECURITY.md)
- Based on: [milon/barcode](https://github.com/milon/barcode): The PHP package whose behaviour this package independently implements, following version 13.6.0.
- PHP parity: full (66 covered, 13 diverged, 0 planned of 79 abilities; 205 fixtures; follows milon/barcode v13.6.0; verified 2026-12-05)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/barcode/docs/getting-started/
- Source: https://github.com/bowerbird-si/laravel-rust-barcode/blob/3cc853b5abd7af2bf6028407dda457fb69bdf231/docs/getting-started.md

Install the framework-free crate and render a Code 39 symbol as SVG or HTML.

```toml
[dependencies]
laravel-rust-barcode-core = "0.1"
```

```rust
use laravel_rust_barcode_core::{Linear, LinearRenderOptions};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let kind: Linear = "C39+".parse()?;
    let symbol = kind.encode("HELLO")?;
    let options = LinearRenderOptions::new().height(60.0).color("#333");

    let svg = symbol.svg(Some("HELLO"), true, options)?;
    let html = symbol.html(Some(("HELLO", 12)), options)?;

    println!("{svg}\n{html}");
    Ok(())
}
```

The SVG call requests inline markup. The HTML call sets a 12 px human-readable label. Omit the
label with `None`. With default rendering options, each narrow module is 2 px wide, the symbol is
30 px high, and the foreground is black.

Encoding returns `EncodeError` for an unknown type name, an invalid byte or a payload above
4096 bytes. Rendering returns `RenderError` for out-of-range dimensions or an invalid colour.
Markup colours accept alphabetic names and hexadecimal RGB.

## QR Code

Use `QrLevel` to encode QR Code Model 2 symbols and `GridStyle` to render them.

```rust
use laravel_rust_barcode_core::{GridStyle, QrLevel};

let code = QrLevel::M.encode("https://example.com")?;
let svg = code.svg(GridStyle::new().module(4, 4).padding(16))?;
# Ok::<(), Box<dyn std::error::Error>>(())
```

The example leaves a four-module quiet zone around the QR Code. The encoder selects the mask
deterministically. A scanner recovers the same payload at the requested error-correction level,
while the selected mask, grid, and version can differ from PHP. SVG and HTML output match PHP
byte for byte when rendered from the same grid and options.

## Data Matrix

Use `encode_data_matrix(payload)` for a square ECC 200 symbol, then render the grid with
`GridStyle`. Leave a quiet zone at least one module wide. PHP and Rust can choose different
compaction modes, so the grid can differ for the same payload.


## PNG and JPEG

Call `png` on a linear or 2D symbol or `jpeg` on a linear symbol. The resulting image exposes the
encoded bytes and a base64 string. Raster images are limited to 4096 pixels per side. The PNG
background defaults to transparent. JPEG uses white. Linear labels use a 7 × 13 bitmap cell.

For a 2D logo, decode the logo bytes with `Logo::decode` and pass it to the grid renderer. Logos
must be PNG, JPEG or GIF, at most 2 MiB and 1024 pixels per side.


## Write images to disk

Create a `Store` with an existing directory and call `write` with the rendered image, the original
payload, the full PHP type string for a 2D barcode, and an optional filename. The store writes the
same bytes as the in-memory image and replaces an existing file atomically. Use the resulting
`StoredBarcode` to get its disk path, public path or public URL.

Default slugs transliterate Latin-1 and Latin Extended-A letters. For a custom name, the store keeps
the final path component and chooses the extension from the rendered format.
