Skip to content

About

Standalone Rust workspace providing a trimmed, QR-reading-only fork of rxing v0.9.0 together with a thin wasm-bindgen wrapper.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

rxing-reader

Standalone Rust workspace providing a trimmed, QR-reading-only fork of rxing v0.9.0 together with a thin wasm-bindgen wrapper.

Crates

  • rxing-reader: the trimmed decoder library. Other formats and the encoder paths from upstream rxing have been removed.
  • rxing-wasm: wasm-bindgen wrapper around rxing-reader. Distributed as a .tgz attached to each GitHub release (not published to the npm registry).
  • rxing-cli: command-line wrapper around rxing-reader. Decodes QR codes from a local image file or an http(s) URL. Prebuilt binaries for linux-amd64, linux-arm64, macos-arm64, and windows-amd64 are attached to each GitHub release.

Using rxing-reader from Rust

Cargo.toml:

[dependencies]
rxing-reader = { git = "https://github.com/andrewtheguy/rxing-reader" }
image = "0.25"

src/main.rs:

use image::ImageReader;
use rxing_reader::{decode_qr_codes_luma, rgba_to_luma};

fn main() {
    let img = ImageReader::open("qr.png").unwrap().decode().unwrap().to_rgba8();
    let (w, h) = (img.width(), img.height());
    let luma = rgba_to_luma(img.as_raw(), w, h).unwrap();

    let results = decode_qr_codes_luma(
        &luma, w, h,
        /* try_harder            */ false,
        /* try_invert            */ false,
        /* use_hybrid_binarizer  */ true,
        /* max_number_of_symbols */ 0,
    ).unwrap();

    for bytes in results {
      println!("{}", String::from_utf8_lossy(&bytes));
    }
}

Using @andrewtheguy/rxing-wasm from JavaScript

The wasm package is not on the npm registry. Install it from the .tgz asset attached to a GitHub release. Pick a release tag, copy the asset URL, and install directly from it:

npm install https://github.com/andrewtheguy/rxing-reader/releases/download/v0.0.3/andrewtheguy-rxing-wasm-0.0.3.tgz

Or pin it in package.json so npm ci is reproducible:

{
  "dependencies": {
    "@andrewtheguy/rxing-wasm": "https://github.com/andrewtheguy/rxing-reader/releases/download/v0.0.3/andrewtheguy-rxing-wasm-0.0.3.tgz"
  }
}

The tarball is the exact wasm-pack output (the contents of rxing-wasm/pkg/); npm unpacks it under the scoped package name from its internal package.json, so imports keep using @andrewtheguy/rxing-wasm:

import init, { read_qr_codes_rgba } from "@andrewtheguy/rxing-wasm";

await init();
const { data, width, height } = ctx.getImageData(0, 0, canvas.width, canvas.height);
const symbols = read_qr_codes_rgba(
    data, width, height,
    /* try_harder            */ false,
    /* try_invert            */ false,
    /* use_hybrid_binarizer  */ true,
    /* binarizer_fallback    */ false,
    /* max_number_of_symbols */ 0,
);
for (const bytes of symbols) {
    console.log(new TextDecoder().decode(bytes));
}

See rxing-wasm/src/lib.rs for the full flag semantics (retry order, binarizer fallback, multi-symbol cap).

Using rxing-cli

Download a prebuilt tarball from a GitHub release and extract the rxing-cli binary:

curl -L https://github.com/andrewtheguy/rxing-reader/releases/download/v0.0.6/rxing-cli-v0.0.6-linux-amd64.tar.gz \
  | tar -xz
./rxing-cli --help

Or build from source:

cargo install --git https://github.com/andrewtheguy/rxing-reader rxing-cli

The CLI accepts a local file path or an http(s) URL and supports two output formats:

# Plain text (default). Caps decode at 1 result; invalid UTF-8 bytes are
# mapped to Latin-1 code points (byte = char). Exits 1 when no QR is found.
rxing-cli qr.png
# jfghjghjghfkghjkghj

# JSON. Returns every detection as an array; each entry has a `text`
# field. Non-ASCII code points are escaped as `\uXXXX` so the wire
# bytes are pure ASCII (matches Python `json.dumps(ensure_ascii=True)`).
rxing-cli --format json https://example.com/qr.png
# [{"text":"https://qr-code-styling.com"},{"text":"jfghjghjghfkghjkghj"}]

# JSON-only: pass --binary to emit every payload as base64 instead of
# text. The choice applies uniformly to every detection in the call, so
# consumers don't have to probe each entry for shape. Combining --binary
# with --format text (or no --format) is rejected with an error.
rxing-cli --format json --binary qr.png
# [{"bytes_b64":"aGVsbG8="}]

Decode-pipeline flags (try_harder, try_invert, binarizer choice, binarizer fallback) are not exposed — the CLI hard-codes the "one-shot image upload" defaults recommended in rxing-wasm/src/lib.rs.

Build and test

cargo clippy --workspace --all-targets
cargo test  --workspace --release

cd rxing-wasm
npm install
npm run build

npm run build invokes the wasm-pack version pinned in rxing-wasm/package-lock.json and writes package artifacts to rxing-wasm/pkg/. Always invoke wasm-pack through npm/npx so the pinned version is used; do not call a system-wide cargo-installed binary.

License

Apache-2.0. See LICENSE.

About

Standalone Rust workspace providing a trimmed, QR-reading-only fork of rxing v0.9.0 together with a thin wasm-bindgen wrapper.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages