Socket
Book a DemoInstallSign in
Socket

wasm-image-processor

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wasm-image-processor

High-performance client-side image processing toolkit powered by Rust and WebAssembly

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
26
-94.41%
Maintainers
1
Weekly downloads
 
Created
Source

WASM Image Processor

Process images offline in the Browser.

⚠️ Early Development Notice: This project is in active development. APIs may change. Use at your own risk for production applications.

A high-performance image processing toolkit built with Rust and WebAssembly. Process images entirely client-side with no server uploads required.

Features

  • Offline Processing: All image operations happen in your browser
  • High Performance: Powered by Rust and WebAssembly
  • No Data Transfer: Images never leave your device
  • PWA Icon Generation: Create complete icon sets for Progressive Web Apps
  • Multiple Formats: Support for JPEG, PNG, WebP, and more
  • Batch Processing: Generate multiple sizes from a single image

Demo

Try the live demo at: https://wasm-ip-demo.vercel.app

  • Basic Resizer: Resize images to custom dimensions
  • PWA Icon Generator: Generate complete icon sets for web apps

Current Features

Image Resizing

  • Resize images to any dimensions up to 5000x5000 pixels
  • Maintain aspect ratio or force specific dimensions
  • High-quality filtering algorithms

Installation

npm i wasm-image-processor

Usage

Include the WASM module in your web page:

import { resize_square } from "wasm-image-processor";

// Example: resize an image uploaded via <input type="file">
const fileInput = document.querySelector<HTMLInputElement>("#fileInput")!;

fileInput.addEventListener("change", () => {
  const file = fileInput.files?.[0]
  if (!file) return

  const reader = new FileReader()
  reader.onload = () => {
    const arrayBuffer = reader.result as ArrayBuffer
    const uint8Array = new Uint8Array(arrayBuffer)

    // Resize to 512x512
    const resizedBytes = resize_square(uint8Array, 512)

    // Create a new File from the resized bytes
    const resizedImage = new File([resizedBytes], "resized.png", {
      type: "image/png",
    })

    console.log("Resized image:", resizedImage)
  }

  reader.readAsArrayBuffer(file)
})

API Reference

resize_square(image_data: Vec<u8>, side: u32) -> Vec<u8>

Resizes an image to a square with the specified side length.

Parameters:

  • image_data: Image data as a byte array
  • side: Target width/height in pixels (1-5000)

Returns:

  • PNG-encoded image data as byte array

Example:

const resizedBytes = resize_square(imageBytes, 256);
const blob = new Blob([new Uint8Array(resizedBytes)], { type: 'image/png' });

Project Structure

wasm-image-processor/
├── src/
│   └─- lib.rs              # Main Rust library
├── demo/
│   ├── index.html          # Basic resizer demo
│   ├── pwa-generator.html  # PWA icon generator
│   ├── pwa_image_generator.js    # Generated JS bindings
│   └── pwa_image_generator_bg.wasm  # Generated WASM binary
├── pkg/                    # wasm-pack output
├── tests/                  # Test files
├── prep-demo.sh            # Copy the build to the demo folder
├── Cargo.toml
└── README.md

Development

Running Tests

# Run Rust tests
cargo test

Adding New Features

The codebase is structured to easily add new image processing functions:

  • Add your function to src/lib.rs
  • Mark it with #[wasm_bindgen]
  • Rebuild with wasm-pack build --target web
  • Update the demo pages to use your new function

Roadmap

Near Term:

  • Stable API design
  • npm package publication
  • Comprehensive documentation
  • CI/CD pipeline

Future Features:

  • Image format conversion (PNG ↔ JPEG ↔ WebP)
  • Image compression with quality settings
  • Batch processing for multiple images
  • Image filters (blur, sharpen, brightness, contrast)
  • Custom crop functionality
  • Image rotation and flipping
  • Metadata preservation and editing
  • Advanced resizing algorithms

Browser Support

  • Chrome/Edge 57+
  • Firefox 52+
  • Safari 11+
  • Any browser with WebAssembly support

Performance

Processing is done entirely client-side using WebAssembly, providing:

  • Fast processing: Near-native performance
  • Privacy: Images never leave your device
  • Offline capability: Works without internet connection
  • Scalability: No server resources required

Contributing

  • Fork the repository
  • Create a feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with Rust and wasm-bindgen
  • Image processing powered by the image crate
  • Inspired by the need for client-side image processing tools

Keywords

wasm

FAQs

Package last updated on 26 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.