npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bgustreadimg-wasm

v0.1.7

Published

WebAssembly build of bgustreadimg for high-performance frontend image preprocessing and Sauvola binarization in the browser.

Readme

bgustreadimg-wasm 🖼️⚡

WebAssembly build of bgustreadimg optimized for high-performance frontend image preprocessing.

This package is a WebAssembly port of the native bgustreadimg library. It brings the power of O(N) Sauvola adaptive binarization and high-quality Lanczos3 resizing directly to modern web browsers, executing pure Rust at near-native speeds.

Use it to clean, resize, and remove uneven shadows, wrinkles, or background noise from camera-captured document images in the browser before running OCR or sending them to backend pipelines.


🚀 Installation

npm install bgustreadimg-wasm

💡 Quick Start

Here is how you can load an image file in the browser, preprocess it using bgustreadimg-wasm, and display it in a <canvas> element.

import init, { preprocessImage } from 'bgustreadimg-wasm';

async function processDocumentImage(imageFile) {
  // 1. Initialize the WebAssembly module
  await init();

  // 2. Read file to ArrayBuffer
  const arrayBuffer = await imageFile.arrayBuffer();
  const inputUint8Array = new Uint8Array(arrayBuffer);

  // 3. Process image (returns Uint8Array of the binarized PNG)
  const windowSize = 25;       // local window size (odd integer >= 3)
  const k = 0.2;               // contrast sensitivity threshold (lower = more aggressive)
  const targetWidth = 800;     // (Optional) target width to resize image (conserving aspect ratio)

  try {
    const outputPngBuffer = preprocessImage(inputUint8Array, windowSize, k, targetWidth);

    // 4. Create image URL and display it
    const blob = new Blob([outputPngBuffer], { type: 'image/png' });
    const imageUrl = URL.createObjectURL(blob);
    
    document.getElementById('output-image').src = imageUrl;
    console.log('Image successfully cleaned in the browser!');
  } catch (error) {
    console.error('Error processing image:', error);
  }
}

🧠 Hybrid Frontend OCR/Layout Inherence

The Rust bgustreadimg native backend supports ONNX-based OCR and document layout analysis. In browser environments, running native ONNX engines via Rust WASM is slow and resource-heavy.

Instead, the recommended hybrid approach is:

  1. Preprocessing (sauvola binarization & resizing): Execute client-side using bgustreadimg-wasm to clean the image inside the browser in milliseconds.
  2. Inference (OCR & Layout): Feed the clean output buffer from bgustreadimg-wasm directly into the JavaScript onnxruntime-web package, which utilizes browser WebGPU or WebGL acceleration for fast, native-speed model execution.

⚙️ API Configuration

preprocessImage(data, windowSize, k, targetWidth)

| Parameter | Type | Default | Description | | :--- | :--- | :--- | :--- | | data | Uint8Array | (Required) | Binary data buffer of the input image (JPEG, PNG, etc.). | | windowSize | number | 25 | Local analysis window size (must be odd and $\ge 3$). | | k | number | 0.2 | Sauvola contrast sensitivity parameter. Smaller values yield more aggressive shadow removal. | | targetWidth | number | 1280 | Maximum width resolution. If the input image is wider, it is scaled down using Lanczos3 resizing. |


📜 License

Distributed under the MIT License. See original repository for details.