Skip to content

Transform

The transform method applies modifications to existing images.

const resized = await floimg.transform(image, {
op: 'resize',
params: { width: 800, height: 600 }
});
ParameterTypeRequiredDescription
imageBlobYesThe image to transform
opstringYesTransform operation name
paramsobjectYesOperation-specific parameters

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 image edges.

await floimg.transform(image, {
op: 'sharpen',
params: {
sigma: 1 // Sharpen intensity
}
});

Change image format.

await floimg.transform(image, {
op: 'convert',
params: {
format: 'webp', // 'png', 'jpeg', 'webp', 'avif'
quality: 80 // 1-100 for lossy formats
}
});

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
}
});

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');