WASM compiled code for libcaesium. This allows you to run (almost) the full libcaesium potential directly inside the browser or in any node.js environment.
Before building this project, make sure you have the following tools installed:
- Rust (Latest stable version recommended)
- Docker (or any alternative you like)
- Cross (For cross-compilation to WASM)
- Node.js (v22 or higher recommended)
-
Clone the repository:
git clone https://github.com/Lymphatus/libcaesium-wasm.git cd libcaesium-wasm
-
Install Node.js dependencies:
npm install
To build both the Rust WASM library and TypeScript bindings:
npm run build
This command will:
- Compile the Rust code to WASM using Cross and Docker (
npm run build:rust
) - Build the TypeScript wrapper and generate type definitions (
npm run build:ts
)
You can also run the build steps individually:
# Build only the Rust WASM library
npm run build:rust
# Build only the TypeScript wrapper
npm run build:ts
After a successful build, you'll find the output files in the dist
directory.
You can test the provided example by running:
# Build the project first
npm run build
# Run the example with an image file
npx tsx examples/example.ts path/to/your/image.jpg
This will output the compressed image in the same folder as the original with the _compressed
suffix.
See the demo here.
initialize()
: Promise that initializes the WASM module. Must be called before using compression functions.compress(imageData: Uint8Array, options: CompressionOptions)
: Compresses an image with the specified options.
interface CompressionOptions {
jpeg: { quality: number; chromaSubsampling: number; progressive: boolean };
png: { quality: number; optimizationLevel: number; forceZopfli: boolean };
webp: { quality: number };
tiff: { compression: number; deflateLevel: number };
gif: { quality: number };
keepMetadata: boolean;
optimize: boolean;
width: number;
height: number;
}
See LICENSE.md for details.