@jspawn/imagecli-wasm

0.1.0 • Public • Published

imagecli-wasm

imagecli compiled to WASM via WASI SDK. This doesn't expose any kind of interface - just the WASM file.

npm install --save @jspawn/imagecli-wasm

Examples

Node

index.mjs

import * as fs from "fs/promises";
// https://nodejs.org/api/wasi.html
import { WASI } from "wasi";

const buf = await fs.readFile(
  "node_modules/@jspawn/imagecli-wasm/imagecli.wasm"
);
const mod = await WebAssembly.compile(buf);

const wasi = new WASI({
  // Create a blank image.
  args: ["imagecli", "-o", "blank.jpg", "-p", "new 100 100 (255, 255, 0)"],
  preopens: {
    ".": ".",
  },
});
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
const instance = await WebAssembly.instantiate(mod, importObject);

// Should be `0` on success.
const exitCode = wasi.start(instance);

Run with:

# Depending on your version of node, you may not need the experimental flags.
node --experimental-wasm-bigint --experimental-wasi-unstable-preview1 index.mjs

Readme

Keywords

none

Package Sidebar

Install

npm i @jspawn/imagecli-wasm

Weekly Downloads

4

Version

0.1.0

License

MIT

Unpacked Size

2.94 MB

Total Files

4

Last publish

Collaborators

  • jsscheller