Export designs to WebP format for optimized web delivery with smaller file sizes than PNG or JPEG.
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 qualityconst 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 |
Combine targetWidth and targetHeight to resize the output, useful for generating thumbnails or optimized versions.
// Export with target dimensionsconst 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 directoryconst 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.