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.
Install the package using npm or yarn:
npm install azion-wasm-image-processor
or
yarn add azion-wasm-image-processor
JavaScript:
import { loadImage } from 'azion/wasm-image-processor';
const image = await loadImage('https://example.com/image.jpg');
TypeScript:
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');
JavaScript:
import { loadImage } from 'azion/wasm-image-processor';
const image = await loadImage('https://example.com/image.jpg');
const resizedImage = image.resize(0.5, 0.5);
TypeScript:
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);
JavaScript:
import { loadImage } from 'azion/wasm-image-processor';
const image = await loadImage('https://example.com/image.jpg');
const imageResponse = image.getImageResponse('jpeg');
console.log(imageResponse);
TypeScript:
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);
JavaScript:
import { loadImage } from 'azion/wasm-image-processor';
const image = await loadImage('https://example.com/image.jpg');
image.clean();
TypeScript:
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();
JavaScript:
import { loadImage, resize, getImageResponse, clean } from 'azion/wasm-image-processor';
const image = await loadImage('https://example.com/image.jpg');
const resizedImage = resize(image.image, 0.5, 0.5);
const imageResponse = getImageResponse(resizedImage, 'jpeg');
console.log(imageResponse);
clean(resizedImage);
TypeScript:
import { loadImage, resize, getImageResponse, clean } from 'azion/wasm-image-processor';
import type { WasmImage, PhotonImage } from 'azion/wasm-image-processor';
const image: WasmImage = await loadImage('https://example.com/image.jpg');
const resizedImage: PhotonImage = resize(image.image, 0.5, 0.5);
const imageResponse: Response = getImageResponse(resizedImage, 'jpeg');
console.log(imageResponse);
clean(resizedImage);
Loads an image from a URL or file path.
Parameters:
pathOrURL: string
- The URL or file path of the image to load.
Returns:
Promise<WasmImage>
- A promise that resolves with aWasmImage
instance.
Resizes the loaded image.
Parameters:
width: number
- The new width of the image.height: number
- The new height of the image.usePercent?: boolean
- Whether to use percentages for resizing. Defaults totrue
.
Returns:
WasmImage
- A newWasmImage
instance with the resized image.
Retrieves the processed image in the specified format.
Parameters:
format: SupportedImageFormat
- The format of the image ('jpeg'
,'png'
,'webp'
).quality?: number
- The quality of the image (for'jpeg'
). Defaults to100.0
.
Returns:
Response
- The response object containing the processed image.
Cleans up the image data to free memory.
Returns:
void
An interface representing a wrapped PhotonImage with additional methods for image processing.
Properties:
image: PhotonImage
- The PhotonImage instance.
Methods:
width(): number
- Gets the width of the image.height(): number
- Gets the height of the image.resize(width: number, height: number, usePercent?: boolean): WasmImage
- Resizes the image.getImageResponse(format: SupportedImageFormat, quality?: number): Response
- Gets the processed image as a response.clean(): void
- Cleans up the image data.
A type representing supported image formats.
'webp'
'jpeg'
'png'
Feel free to submit issues or pull requests to improve the functionality or documentation.