# wasm-image

> an image manipulation wrapper, JS API for Rust image

Latest version **0.1.0** (published 2019-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install wasm-image
pnpm add wasm-image
yarn add wasm-image
bun add wasm-image
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2019-04-09 |
| First published | 2019-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 733.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 43 |
| Author | Peerigon GmbH |
| Maintainers | acidicx |
| Keywords | image, wasm, rust, typescript |

## Links

- npm: https://www.npmjs.com/package/wasm-image
- Repository: https://github.com/peerigon/wasm-image
- Homepage: https://github.com/peerigon/wasm-image#readme
- Issues: https://github.com/peerigon/wasm-image/issues
- npm.io page: https://npm.io/package/wasm-image

## Dependencies (1)

- [wasm-rust-image](https://npm.io/package/wasm-rust-image.md) file:rust-image-wrapper/pkg

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2019-04-09

## README

# wasm-image

blazing fast image processing in WebAssembly

:warning: Please check the limitations. This is still a work in progress!

## Install

```bash
npm i wasm-image
# or
yarn install wasm-image
```

If you want to use it in a frontend web project, please make sure you use a module bundler that supports WebAssembly, like [webpack](https://webpack.js.org/).

WebAssembly is supported in [all modern browsers](https://caniuse.com/#feat=wasm).

## Usage

The small JavaScript wrapper on top of the WASM module is `src/image.ts`. As WASM with shared memory is not well supported yet, you need to load the image into the wrapper first:

```ts
import { WasmImage } from "wasm-image";

const WasmImg = new WasmImage();
WasmImg.setImage(new Uint8Array(buffer));
```

Note: you can convert a file into a conforming buffer like this:

<details>

```ts
getImageAsArrayBuffer = async (file: File): Promise<ArrayBuffer> => {
  const result = await new Promise<ArrayBuffer>((resolve, reject) => {
    const reader = new FileReader();
    reader.onloadend = () => {
      if (reader.result instanceof ArrayBuffer) {
        return resolve(reader.result);
      } else {
        return reject(new Error("Could not create arraybuffer"));
      }
    };
    reader.onerror = reject;
    reader.readAsArrayBuffer(file);
  });

  return result;
};
```

</details>

Afterwards, you can execute as many operations as you want on the image:

```ts
await WasmImg.rotate(90);
await WasmImg.brighten(1);
...
```

Afterwards you can retrieve your image from WebAssembly:

```ts
const modifiedImage: Uint8Array = await WasmImg.getImage();
```

## Supported image operations
Please check our [docs](https://peerigon.github.io/wasm-image/) for all available image processing functions.

## Limitations

The Rust library used for this project is [image](https://github.com/PistonDevelopers/image). All limitations that are mentioned for this library are obviously also valid for this WASM wrapper.

Please make sure you read the [list of supported image formts](https://github.com/PistonDevelopers/image#2-supported-image-formats).

### WARNING
The package currently only supports PNG, the rest is a work in progress.

## License

MIT

## Sponsors

[<img src="https://assets.peerigon.com/peerigon/logo/peerigon-logo-flat-spinat.png" width="150" />](https://peerigon.com)

---
_Source: https://npm.io/package/wasm-image · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
