WASM Image Processor library

The Azion WASM Image Processor Library provides functions to process images using WebAssembly. This library allows you to load, resize, and retrieve images in various formats efficiently.

Go to Azion Libraries Overview

Usage

loadImage

Loads an image from a URL or file path.

Example:

import { loadImage } from 'azion/wasm-image-processor';
import type { WasmImage } from 'azion/wasm-image-processor';
const image: WasmImage = await loadImage('https://example.com/image.jpg');

Parameters:

ParameterTypeDescription
pathOrURLstringThe URL or file path of the image to be loaded.

Returns:

Return TypeDescription
Promise<WasmImage>A promise that resolves with a WasmImage instance.

resize

Resizes the loaded image.

Example:

import { loadImage } from 'azion/wasm-image-processor';
import type { WasmImage } from 'azion/wasm-image-processor';
const image: WasmImage = await loadImage('https://example.com/image.jpg');
const resizedImage: WasmImage = image.resize(0.5, 0.5);

Parameters:

ParameterTypeDescription
widthnumberThe new width of the image.
heightnumberThe new height of the image.
usePercent?booleanWhether to use percentages for resizing. Default value: true.

Returns:

Return TypeDescription
WasmImageA new WasmImage instance with the resized image.

getImageResponse

Retrieves the processed image in the specified format.

Example:

import { loadImage } from 'azion/wasm-image-processor';
import type { WasmImage, SupportedImageFormat } from 'azion/wasm-image-processor';
const image: WasmImage = await loadImage('https://example.com/image.jpg');
const imageResponse: Response = image.getImageResponse('jpeg' as SupportedImageFormat);
console.log(imageResponse);

Parameters:

ParameterTypeDescription
formatSupportedImageFormatThe format of the image. Example: 'jpeg', 'png', 'webp'.
quality?numberThe quality of the image (for 'jpeg'). Default value: 100.0.

Returns:

Return TypeDescription
ResponseThe response object containing the processed image.

clean

Cleans up the image data to free memory.

Example:

import { loadImage } from 'azion/wasm-image-processor';
import type { WasmImage, SupportedImageFormat } from 'azion/wasm-image-processor';
const image: WasmImage = await loadImage('https://example.com/image.jpg');
image.clean();

Returns:

Return TypeDescription
voidNo return value.

Types

These are the types used by the WASM Image Processor library and its methods:

WasmImage

An interface representing a wrapped PhotonImage with additional methods for image processing.

Properties:

PropertyDescription
imageThe PhotonImage instance.

Methods:

MethodParametersReturn TypeDescription
width-numberGets the width of the image.
height-numberGets the height of the image.
resizewidth: number, height: number, usePercent?: booleanWasmImageResizes the image.
getImageResponseformat: SupportedImageFormat, quality?: numberResponseGets the processed image as a response.
clean-voidCleans up the image data.

SupportedImageFormat

A type representing supported image formats. The possible values are:

  • 'webp'
  • 'jpeg'
  • 'png'

Contributors