open-index/open-npm huggingface dataset:
npm package: @radulle/cra-squoosh-avif
Description: Wasm AVIF encoder and decoder supporting the browser. Repackaged from Squoosh App, CRA compatible fork.
Author: Jamie Sinclair
Latest version: 1.0.2

# @jsquash/avif

An easy experience for encoding and decoding AVIF images in the browser. Powered by WebAssembly ⚡️.

Uses the [libavif](https://github.com/AOMediaCodec/libavif) library.

A [jSquash](https://github.com/jamsinclair/jSquash) package. Codecs and supporting code derived from the [Squoosh](https://github.com/GoogleChromeLabs/squoosh) app.

## Installation

```shell
npm install --save @jsquash/avif
# Or your favourite package manager alternative
```

## Usage

Note: You will need to either manually include the wasm files from the codec directory or use a bundler like WebPack or Rollup to include them in your app/server.

### decode(data: ArrayBuffer): Promise<ImageData>

Decodes AVIF binary ArrayBuffer to raw RGB image data.

#### data
Type: `ArrayBuffer`

#### Example
```js
import { decode } from '@jsquash/avif';

const formEl = document.querySelector('form');
const formData = new FormData(formEl);
// Assuming user selected an input avif file
const imageData = await decode(await formData.get('image').arrayBuffer());
```

### encode(data: ImageData, options?: EncodeOptions): Promise<ArrayBuffer>

Encodes raw RGB image data to AVIF format and resolves to an ArrayBuffer of binary data.

#### data
Type: `ImageData`

#### options
Type: `Partial<EncodeOptions>`

The AVIF encoder options for the output image. [See default values](./meta.ts).

#### Example
```js
import { encode } from '@jsquash/avif';

async function loadImage(src) {
  const img = document.createElement('img');
  img.src = src;
  await new Promise(resolve => img.onload = resolve);
  const canvas = document.createElement('canvas');
  [canvas.width, canvas.height] = [img.width, img.height];
  const ctx = canvas.getContext('2d');
  ctx.drawImage(img, 0, 0);
  return ctx.getImageData(0, 0, img.width, img.height);
}

const rawImageData = await loadImage('/example.png');
const avifBuffer = await encode(rawImageData);
```

## Manual WASM initialisation (not recommended)

In most situations there is no need to manually initialise the provided WebAssembly modules.
The generated glue code takes care of this and supports most web bundlers.

One exception is CloudFlare workers. The environment at this time (this could change in the future) does not allow code to be dynamically imported. It needs to be bundled at runtime. WASM modules are set as global variables. [See the Cloudflare workers example](examples/cloudflare-worker).

The `encode` and `decode` modules both export an `init` function that can be used to manually load the wasm module.

```js
import decode, { init as initAvifDecode } from '@jsquash/avif/decode';

const WASM_MODULE = // A WebAssembly.Module object of the compiled wasm binary
initAvifDecode(WASM_MODULE);
const image = await fetch('./image.avif').then(res => res.arrayBuffer()).then(decode);
```
npm package: @radulle/cra-squoosh-jpeg
Description: Wasm jpeg encoder and decoder supporting the browser. Repackaged from Squoosh App, CRA compatible fork.
Author: Jamie Sinclair
Latest version: 1.1.5

# @jsquash/jpeg

An easy experience for encoding and decoding JPEG images in the browser. Powered by WebAssembly ⚡️.

Uses the [MozJPEG](https://github.com/mozilla/mozjpeg) library.

A [jSquash](https://github.com/jamsinclair/jSquash) package. Codecs and supporting code derived from the [Squoosh](https://github.com/GoogleChromeLabs/squoosh) app.

## Installation

```shell
npm install --save @jsquash/jpeg
# Or your favourite package manager alternative
```

## Usage

Note: You will need to either manually include the wasm files from the codec directory or use a bundler like WebPack or Rollup to include them in your app/server.

### decode(data: ArrayBuffer): Promise<ImageData>

Decodes JPEG binary ArrayBuffer to raw RGB image data.

#### data
Type: `ArrayBuffer`

#### Example
```js
import { decode } from '@jsquash/jpeg';

const formEl = document.querySelector('form');
const formData = new FormData(formEl);
// Assuming user selected an input jpeg file
const imageData = await decode(await formData.get('image').arrayBuffer());
```

### encode(data: ImageData, options?: EncodeOptions): Promise<ArrayBuffer>

Encodes raw RGB image data to JPEG format and resolves to an ArrayBuffer of binary data.

#### data
Type: `ImageData`

#### options
Type: `Partial<EncodeOptions>`

The MozJPEG encoder options for the output image. [See default values](./meta.ts).

#### Example
```js
import { encode } from '@jsquash/jpeg';

async function loadImage(src) {
  const img = document.createElement('img');
  img.src = src;
  await new Promise(resolve => img.onload = resolve);
  const canvas = document.createElement('canvas');
  [canvas.width, canvas.height] = [img.width, img.height];
  const ctx = canvas.getContext('2d');
  ctx.drawImage(img, 0, 0);
  return ctx.getImageData(0, 0, img.width, img.height);
}

const rawImageData = await loadImage('/example.png');
const jpegBuffer = await encode(rawImageData);
```

## Manual WASM initialisation (not recommended)

In most situations there is no need to manually initialise the provided WebAssembly modules.
The generated glue code takes care of this and supports most web bundlers.

One exception is CloudFlare workers. The environment at this time (this could change in the future) does not allow code to be dynamically imported. It needs to be bundled at runtime. WASM modules are set as global variables. [See the Cloudflare workers example](examples/cloudflare-worker).

The `encode` and `decode` modules both export an `init` function that can be used to manually load the wasm module.

```js
import decode, { init as initJpegDecode } from '@jsquash/jpeg/decode';

const WASM_MODULE = // A WebAssembly.Module object of the compiled wasm binary
initJpegDecode(WASM_MODULE);
const image = await fetch('./image.jpeg').then(res => res.arrayBuffer()).then(decode);
```
npm package: @radulle/cra-squoosh-oxipng
Description: Wasm png optimiser supporting the browser. Repackaged from Squoosh App, CRA compatible fork.
Author: Jamie Sinclair
Latest version: 1.0.2

# @jsquash/oxipng

An easy experience for optimising PNG images in the browser. Powered by WebAssembly ⚡️ and Rust.

Uses the lovely [Oxipng](https://github.com/shssoichiro/oxipng) for png optimisation.

A [jSquash](https://github.com/jamsinclair/jSquash) package. Codecs and supporting code derived from the [Squoosh](https://github.com/GoogleChromeLabs/squoosh) app.

## Installation

```shell
npm install --save @jsquash/oxipng
# Or your favourite package manager alternative
```

## Usage

Note: You will need to either manually include the wasm files from the codec directory or use a bundler like WebPack or Rollup to include them in your app/server.

### optimise(data: ArrayBuffer, options?: OptimiseOptions): Promise<ArrayBuffer>

Optimises a PNG image buffer and resolves to the optimised buffer output

#### data
Type: `ArrayBuffer`

#### options
Type: `Partial<OptimiseOptions>`

The Oxipng optimisation options for the output image. [See default values](./meta.ts).
- `interlace` (boolean) whether to use PNG interlacing or not. Interlacing will increase the size of an optimised image.
- `level` (number) is the optimisation level between 1 to 6. The higher the level, the higher the compression. Any level above 4 is not recommended.


#### Example
```js
import { optimise } from '@jsquash/oxipng';

const formEl = document.querySelector('form');
const formData = new FormData(formEl);
// Assuming user selected an input png file
const pngImageBuffer = await formData.get('image').arrayBuffer();

const optimisedPngBuffer = await optimise(pngImageBuffer, { level: 3 });
```

## Manual WASM initialisation (not recommended)

In most situations there is no need to manually initialise the provided WebAssembly modules.
The generated glue code takes care of this and supports most web bundlers.

One exception is CloudFlare workers. The environment at this time (this could change in the future) does not allow code to be dynamically imported. It needs to be bundled at runtime. WASM modules are set as global variables. [See the Cloudflare workers example](examples/cloudflare-worker).

The `optimise` module exports an `init` function that can be used to manually load the wasm module.

```js
import optimise, { init } from '@jsquash/oxipng/optimise';

const WASM_MODULE = // A WebAssembly.Module object of the compiled wasm binary
init(WASM_MODULE);
const image = await fetch('./image.png').then(res => res.arrayBuffer()).then(optimise);
```
npm package: @radulle/cra-squoosh-png
Description: Wasm png encoder and decoder supporting the browser. Repackaged from Squoosh App, CRA compatible fork.
Author: Jamie Sinclair
Latest version: 2.0.0

# @jsquash/png

An easy experience for encoding and decoding PNG images in the browser. Powered by WebAssembly ⚡️.

Uses the [rust PNG crate](https://docs.rs/png/0.11.0/png/).

A [jSquash](https://github.com/jamsinclair/jSquash) package. Codecs and supporting code derived from the [Squoosh](https://github.com/GoogleChromeLabs/squoosh) app.

## Installation

```shell
npm install --save @jsquash/png
# Or your favourite package manager alternative
```

## Usage

Note: You will need to either manually include the wasm files from the codec directory or use a bundler like WebPack or Rollup to include them in your app/server.

### decode(data: ArrayBuffer): Promise<ImageData>

Decodes PNG binary ArrayBuffer to raw RGB image data.

#### data
Type: `ArrayBuffer`

#### Example
```js
import { decode } from '@jsquash/png';

const formEl = document.querySelector('form');
const formData = new FormData(formEl);
const imageData = await decode(await formData.get('image').arrayBuffer());
```

### encode(data: ImageData): Promise<ArrayBuffer>

Encodes raw RGB image data to PNG format and resolves to an ArrayBuffer of binary data.

#### data
Type: `ImageData`

#### Example
```js
import { encode } from '@jsquash/png';

async function loadImage(src) {
  const img = document.createElement('img');
  img.src = src;
  await new Promise(resolve => img.onload = resolve);
  const canvas = document.createElement('canvas');
  [canvas.width, canvas.height] = [img.width, img.height];
  const ctx = canvas.getContext('2d');
  ctx.drawImage(img, 0, 0);
  return ctx.getImageData(0, 0, img.width, img.height);
}

const rawImageData = await loadImage('/example.jpg');
const pngBuffer = await encode(rawImageData);
```

## Manual WASM initialisation (not recommended)

In most situations there is no need to manually initialise the provided WebAssembly modules.
The generated glue code takes care of this and supports most web bundlers.

One exception is CloudFlare workers. The environment at this time (this could change in the future) does not allow code to be dynamically imported. It needs to be bundled at runtime. WASM modules are set as global variables. [See the Cloudflare workers example](examples/cloudflare-worker).

The `encode` and `decode` modules both export an `init` function that can be used to manually load the wasm module.

```js
import decode, { init as initPngDecode } from '@jsquash/png/decode';

const WASM_MODULE = // A WebAssembly.Module object of the compiled wasm binary
initPngDecode(WASM_MODULE);
const image = await fetch('./image.png').then(res => res.arrayBuffer()).then(decode);
```
npm package: @radulle/cra-squoosh-resize
Description: Wasm image resize methods supporting the browser and V8 environments. Repackaged from Squoosh App, CRA compatible fork.
Author: Jamie Sinclair
Latest version: 1.0.2

# @jsquash/resize

An easy experience for resizing images in the browser or V8 environment. Powered by WebAssembly ⚡️ and Rust.

ℹ️ You will need to have an already decoded ImageData object to resize. This can be accomplished by using other jSquash modules or using the Canvas API, if available.

Uses squoosh's [Resize module](https://github.com/GoogleChromeLabs/squoosh/blob/dev/src/features/processors/resize/worker/resize.ts).
Composed of:
- https://github.com/PistonDevelopers/resize
- https://github.com/CryZe/wasmboy-rs/tree/master/hqx

A [jSquash](https://github.com/jamsinclair/jSquash) package. Codecs and supporting code derived from the [Squoosh](https://github.com/GoogleChromeLabs/squoosh) app.

## Installation

```shell
npm install --save @jsquash/resize
# Or your favourite package manager alternative
```

## Usage

Note: You will need to either manually include the wasm files from the codec directory or use a bundler like WebPack or Rollup to include them in your app/server.

### resize(data: ImageData, options: ResizeOptions): Promise<ImageData>

Resizes an ImageData object to the 

#### data
Type: `ImageData`

#### options
Type: `Partial<ResizeOptions> & { width: number, height: number }`

The resize options for the output image. [See default values](./meta.ts).
- `width` (number) the width to resize the image to 
- `height` (number) the height to resize the image to
- `method?` (`'triangle'` | `'catrom'` | `'mitchell'` | `'lanczos3'` | `'hqx'`) the algorithm used to resize the image. Defaults to `lanczos3`.
- `fitMethod?` (`'stretch'` | `'contain'`) whether the image is stretched to fit the dimensions or cropped. Defaults to `stretch`.
- `premultiply?` (boolean) Defaults to `true`
- `linearRGB?` (boolean) Defaults to `true`


#### Example
```js
import { decode } from '@jsquash/jpeg';
import resize from '@jsquash/resize';

const imageBuffer = fetch('/images/example.jpg').then(res => res.arrayBuffer());
const originalImageData = await decode(imageBuffer);
const resizedImageData = await resize(originalImageData, { height: 300, width: 400 };
```

## Manual WASM initialisation (not recommended)

In most situations there is no need to manually initialise the provided WebAssembly modules.
The generated glue code takes care of this and supports most web bundlers.

One exception is CloudFlare workers. The environment at this time (this could change in the future) does not allow code to be dynamically imported. It needs to be bundled at runtime. WASM modules are set as global variables. [See the Cloudflare workers example](examples/cloudflare-worker).

The main module exports `initHqx` and `initResize` functions that can be used to manually load their respective wasm module.

```js
import resize, { initResize } from '@jsquash/resize';

const WASM_MODULE = // A WebAssembly.Module object of the compiled wasm binary
initResize(WASM_MODULE);

resize(image, options);
```
npm package: @radulle/cra-squoosh-webp
Description: Wasm webp encoder and decoder supporting the browser. Repackaged from Squoosh App, CRA compatible fork.
Author: Jamie Sinclair
Latest version: 1.1.3

# @jsquash/webp

An easy experience for encoding and decoding WebP images in the browser. Powered by WebAssembly ⚡️.

Uses the [libwebp](https://github.com/webmproject/libwebp) library.

A [jSquash](https://github.com/jamsinclair/jSquash) package. Codecs and supporting code derived from the [Squoosh](https://github.com/GoogleChromeLabs/squoosh) app.

## Installation

```shell
npm install --save @jsquash/webp
# Or your favourite package manager alternative
```

## Usage

Note: You will need to either manually include the wasm files from the codec directory or use a bundler like WebPack or Rollup to include them in your app/server.

### decode(data: ArrayBuffer): Promise<ImageData>

Decodes WebP binary ArrayBuffer to raw RGB image data.

#### data
Type: `ArrayBuffer`

#### Example
```js
import { decode } from '@jsquash/webp';

const formEl = document.querySelector('form');
const formData = new FormData(formEl);
// Assuming user selected an input WebP file
const imageData = await decode(await formData.get('image').arrayBuffer());
```

### encode(data: ImageData, options?: EncodeOptions): Promise<ArrayBuffer>

Encodes raw RGB image data to WebP format and resolves to an ArrayBuffer of binary data.

#### data
Type: `ImageData`

#### options
Type: `Partial<EncodeOptions>`

The WebP encoder options for the output image. [See default values](./meta.ts).

#### Example
```js
import { encode } from '@jsquash/webp';

async function loadImage(src) {
  const img = document.createElement('img');
  img.src = src;
  await new Promise(resolve => img.onload = resolve);
  const canvas = document.createElement('canvas');
  [canvas.width, canvas.height] = [img.width, img.height];
  const ctx = canvas.getContext('2d');
  ctx.drawImage(img, 0, 0);
  return ctx.getImageData(0, 0, img.width, img.height);
}

const rawImageData = await loadImage('/example.png');
const webpBuffer = await encode(rawImageData);
```

## Manual WASM initialisation (not recommended)

In most situations there is no need to manually initialise the provided WebAssembly modules.
The generated glue code takes care of this and supports most web bundlers.

One exception is CloudFlare workers. The environment at this time (this could change in the future) does not allow code to be dynamically imported. It needs to be bundled at runtime. WASM modules are set as global variables. [See the Cloudflare workers example](examples/cloudflare-worker).

The `encode` and `decode` modules both export an `init` function that can be used to manually load the wasm module.

```js
import decode, { init as initWebpDecode } from '@jsquash/webp/decode';

const WASM_MODULE = // A WebAssembly.Module object of the compiled wasm binary
initWebpDecode(WASM_MODULE);
const image = await fetch('./image.webp').then(res => res.arrayBuffer()).then(decode);
```