Search Docs
Loading...
Skip to content

To WebP

Export designs to WebP format for optimized web delivery with smaller file sizes than PNG or JPEG.

5 mins
estimated time
Download
StackBlitz
GitHub

WebP delivers smaller file sizes than PNG and JPEG while preserving image quality and transparency support. This makes it ideal for server-side processing where bandwidth and storage costs matter.

This guide covers exporting to WebP, configuring quality settings, and saving files to disk.

Export to WebP#

Call engine.block.export() with mimeType: 'image/webp' and a webpQuality value between 0 and 1.

// Export to WebP with selected quality
const stopExport = showLoading('Exporting to WebP...');
const webpBlob = await engine.block.export(page, {
mimeType: 'image/webp',
webpQuality: selected.quality
});
stopExport();

The webpQuality parameter controls compression. A value of 0.8 provides a good balance between file size and visual quality for most use cases.

Export Options#

WebP export supports these options:

Option Type Description
mimeType 'image/webp' Required. Specifies WebP format
webpQuality number Quality from 0 to 1. Default 1.0 (lossless)
targetWidth number Optional resize width
targetHeight number Optional resize height
outputProfileMode string What the export does with the document’s Output RGB profile. 'Off' (default) ignores it. 'Convert' converts the pixels into it, and writes the profile only with embedProfiles. 'Assign' keeps the pixels and writes the profile into the file, also without embedProfiles. See Color Basics.
embedProfiles boolean Write an ICC profile into the file: the Output RGB profile under 'Convert' or 'Assign', else the profile of the working space. Defaults to false.

Combine targetWidth and targetHeight to resize the output, useful for generating thumbnails or optimized versions.

// Export with target dimensions
const resizedBlob = await engine.block.export(page, {
mimeType: 'image/webp',
webpQuality: selected.quality,
targetWidth: 1200,
targetHeight: 630
});

Set webpQuality to 1.0 for lossless compression when pixel-perfect output is required.

Save to File#

Convert the exported blob to a buffer and write it to disk.

// Save to output directory
const buffer = Buffer.from(await webpBlob.arrayBuffer());
const filename = `design-${selected.name}.webp`;
writeFileSync(`${outputDir}/${filename}`, buffer);

The export returns a Blob. Convert it to an ArrayBuffer, then wrap in a Buffer for Node.js file system operations.

API Reference#

API Description
engine.block.export() Exports a block to an image blob with format and quality options
writeFileSync() Node.js API to write buffer data to a file
Buffer.from() Converts ArrayBuffer to Node.js Buffer for file operations

Next Steps#

Export Overview - Learn about all supported export formats and their options.

Export to PDF - Generate print-ready PDF documents from your designs.

Size Limits - Understand export size constraints and optimization strategies.

Partial Export - Export specific blocks or regions instead of the full design.