# `@wordpress/vips`

Helper package to interact with [`wasm-vips`](https://github.com/kleisauke/wasm-vips).

## Installation

Install the module

```bash
npm install @wordpress/vips --save
```

## API Reference

<!-- START TOKEN(Autogenerated API docs) -->

### cancelOperations

Cancels all ongoing image operations for a given item ID.

The onProgress callbacks check for an IDs existence in this list, killing the process if it's absent.

_Parameters_

-   _id_ `ItemId`: Item ID.

_Returns_

-   boolean Whether any operation was cancelled.

### compressImage

Compresses an existing image using vips.

_Parameters_

-   _id_ `ItemId`: Item ID.
-   _buffer_ `ArrayBuffer`: Original file buffer.
-   _type_ `string`: Mime type.
-   _quality_ Desired quality.
-   _interlaced_ Whether to use interlaced/progressive mode. Only used if the outputType supports it.

_Returns_

-   `Promise< ArrayBuffer | ArrayBufferLike >`: Compressed file data.

### convertImageFormat

Converts an image to a different format using vips.

_Parameters_

-   _id_ `ItemId`: Item ID.
-   _buffer_ `ArrayBuffer`: Original file buffer.
-   _inputType_ `string`: Input mime type.
-   _outputType_ `string`: Output mime type.
-   _quality_ Desired quality.
-   _interlaced_ Whether to use interlaced/progressive mode. Only used if the outputType supports it.

### hasTransparency

Determines whether an image has an alpha channel.

_Parameters_

-   _buffer_ `ArrayBuffer`: Original file object.

_Returns_

-   `Promise< boolean >`: Whether the image has an alpha channel.

### resizeImage

Resizes an image using vips.

_Parameters_

-   _id_ `ItemId`: Item ID.
-   _buffer_ `ArrayBuffer`: Original file buffer.
-   _type_ `string`: Mime type.
-   _resize_ `ImageSizeCrop`: Resize options.
-   _smartCrop_ Whether to use smart cropping (i.e. saliency-aware).

_Returns_

-   `Promise< { buffer: ArrayBuffer | ArrayBufferLike; width: number; height: number; originalWidth: number; originalHeight: number; } >`: Processed file data plus the old and new dimensions.

### rotateImage

Rotates an image based on EXIF orientation value.

EXIF orientation values: 1 = Normal (no rotation needed) 2 = Flipped horizontally 3 = Rotated 180° 4 = Flipped vertically 5 = Rotated 90° CCW and flipped horizontally 6 = Rotated 90° CW 7 = Rotated 90° CW and flipped horizontally 8 = Rotated 90° CCW

_Parameters_

-   _id_ `ItemId`: Item ID.
-   _buffer_ `ArrayBuffer`: Original file buffer.
-   _type_ `string`: Mime type.
-   _orientation_ `number`: EXIF orientation value (1-8).

_Returns_

-   `Promise< { buffer: ArrayBuffer | ArrayBufferLike; width: number; height: number; } >`: Rotated file data plus the new dimensions.

### vipsCancelOperations

Cancels all ongoing image operations for a given item ID.

The onProgress callbacks check for an IDs existence in this list, killing the process if it's absent.

_Parameters_

-   _id_ `ItemId`: Item ID.

_Returns_

-   boolean Whether any operation was cancelled.

### vipsCompressImage

Compresses an existing image using vips.

_Parameters_

-   _id_ `ItemId`: Item ID.
-   _buffer_ `ArrayBuffer`: Original file buffer.
-   _type_ `string`: Mime type.
-   _quality_ Desired quality.
-   _interlaced_ Whether to use interlaced/progressive mode. Only used if the outputType supports it.

_Returns_

-   `Promise< ArrayBuffer | ArrayBufferLike >`: Compressed file data.

### vipsConvertImageFormat

Converts an image to a different format using vips.

_Parameters_

-   _id_ `ItemId`: Item ID.
-   _buffer_ `ArrayBuffer`: Original file buffer.
-   _inputType_ `string`: Input mime type.
-   _outputType_ `string`: Output mime type.
-   _quality_ Desired quality.
-   _interlaced_ Whether to use interlaced/progressive mode. Only used if the outputType supports it.

### vipsHasTransparency

Determines whether an image has an alpha channel.

_Parameters_

-   _buffer_ `ArrayBuffer`: Original file object.

_Returns_

-   `Promise< boolean >`: Whether the image has an alpha channel.

### vipsResizeImage

Resizes an image using vips.

_Parameters_

-   _id_ `ItemId`: Item ID.
-   _buffer_ `ArrayBuffer`: Original file buffer.
-   _type_ `string`: Mime type.
-   _resize_ `ImageSizeCrop`: Resize options.
-   _smartCrop_ Whether to use smart cropping (i.e. saliency-aware).

_Returns_

-   `Promise< { buffer: ArrayBuffer | ArrayBufferLike; width: number; height: number; originalWidth: number; originalHeight: number; } >`: Processed file data plus the old and new dimensions.

### vipsRotateImage

Rotates an image based on EXIF orientation value.

EXIF orientation values: 1 = Normal (no rotation needed) 2 = Flipped horizontally 3 = Rotated 180° 4 = Flipped vertically 5 = Rotated 90° CCW and flipped horizontally 6 = Rotated 90° CW 7 = Rotated 90° CW and flipped horizontally 8 = Rotated 90° CCW

_Parameters_

-   _id_ `ItemId`: Item ID.
-   _buffer_ `ArrayBuffer`: Original file buffer.
-   _type_ `string`: Mime type.
-   _orientation_ `number`: EXIF orientation value (1-8).

_Returns_

-   `Promise< { buffer: ArrayBuffer | ArrayBufferLike; width: number; height: number; } >`: Rotated file data plus the new dimensions.

<!-- END TOKEN(Autogenerated API docs) -->
