Skip to main content

Package installation

Install kimg from npm using your preferred package manager:
npm install @iamkaf/kimg
kimg works identically in Node.js and the browser with no additional configuration required.

Prerequisites

kimg has minimal runtime prerequisites:
  • Node.js: Version 18 or later (for Node.js usage)
  • Modern browser: Any browser with WebAssembly support (for browser usage)
No native dependencies or build tools are required for using the package.

Verification

Verify your installation by checking if you can import the main module:
import { Composition } from '@iamkaf/kimg';

const doc = await Composition.create({ width: 128, height: 128 });
console.log(`Created composition: ${doc.width}x${doc.height}`);
If this runs without errors, kimg is installed correctly.

Development setup (building from source)

If you want to contribute to kimg or build from source, you’ll need additional tools:

Prerequisites for development

  • Node.js and npm
  • Rust (latest stable version)
  • wasm32-unknown-unknown target
  • wasm-bindgen-cli

Installation steps

1

Clone the repository

git clone https://github.com/iamkaf/kimg.git
cd kimg
2

Install Node.js dependencies

npm install
3

Install Rust target

Add the WebAssembly compilation target:
rustup target add wasm32-unknown-unknown
4

Install wasm-bindgen-cli

cargo install wasm-bindgen-cli
5

Build the project

Run the build script to compile the WASM binaries and TypeScript wrapper:
./scripts/build.sh
This builds the consumable JS/WASM package into dist/.

Build output

The build process generates:
  • dist/index.js — Main JavaScript entry point
  • dist/kimg_wasm_bg.wasm — Baseline WASM binary
  • dist/kimg_wasm_simd_bg.wasm — SIMD-optimized WASM binary
  • dist/*.d.ts — TypeScript type definitions
The package automatically selects the SIMD binary when the runtime supports it, providing better performance without manual configuration.

WASM initialization

kimg automatically initializes the WASM module when you create your first composition. For advanced use cases, you can manually preload the WASM module:
import preload from '@iamkaf/kimg';

// Preload WASM module
await preload();

// Now create compositions
const doc = await Composition.create({ width: 128, height: 128 });

Custom WASM path

In Node.js environments with custom module resolution, you can provide a custom WASM path:
import { readFileSync } from 'node:fs';
import preload from '@iamkaf/kimg';

const wasm = readFileSync('./path/to/kimg_wasm_bg.wasm');
await preload({ module_or_path: wasm });

Subpath exports

kimg provides several subpath exports for specific functionality:
// Base64 RGBA helpers (pure JS, no WASM init needed)
import { rgbaToBase64, base64ToRgba } from '@iamkaf/kimg/base64';

// Readable text color picker
import { readableTextColor } from '@iamkaf/kimg/color-utils';

// Low-level WASM API (browser)
import initRaw, { Composition as RawComposition } from '@iamkaf/kimg/raw';

Next steps

Quickstart

Get your first composition working with real examples

Build docs developers (and LLMs) love