Transform
The transform method applies modifications to existing images.
Basic Usage
Section titled “Basic Usage”const resized = await floimg.transform(image, { op: 'resize', params: { width: 800, height: 600 }});Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
image | Blob | Yes | The image to transform |
op | string | Yes | Transform operation name |
params | object | Yes | Operation-specific parameters |
Available Transforms
Section titled “Available Transforms”resize
Section titled “resize”Change image dimensions.
await floimg.transform(image, { op: 'resize', params: { width: 800, // Target width in pixels height: 600, // Target height in pixels (optional) fit: 'cover' // How to fit: 'cover', 'contain', 'fill', 'inside', 'outside' }});Apply gaussian blur.
await floimg.transform(image, { op: 'blur', params: { sigma: 5 // Blur intensity (1-100) }});sharpen
Section titled “sharpen”Sharpen image edges.
await floimg.transform(image, { op: 'sharpen', params: { sigma: 1 // Sharpen intensity }});convert
Section titled “convert”Change image format.
await floimg.transform(image, { op: 'convert', params: { format: 'webp', // 'png', 'jpeg', 'webp', 'avif' quality: 80 // 1-100 for lossy formats }});rotate
Section titled “rotate”Rotate the image.
await floimg.transform(image, { op: 'rotate', params: { angle: 90 // Degrees (90, 180, 270, or any angle) }});Crop to a region.
await floimg.transform(image, { op: 'crop', params: { left: 100, top: 100, width: 400, height: 300 }});Chaining Transforms
Section titled “Chaining Transforms”Transforms can be chained:
let image = await floimg.generate({ ... });
image = await floimg.transform(image, { op: 'resize', params: { width: 800 } });image = await floimg.transform(image, { op: 'blur', params: { sigma: 2 } });image = await floimg.transform(image, { op: 'convert', params: { format: 'webp' } });
await floimg.save(image, './output.webp');