Search Docs
Loading...
Skip to content

To WebP

Export CE.SDK designs to WebP format for compact image files that preserve transparency, with a single quality knob spanning lossy and lossless modes.

5 mins
estimated time
GitHub

WebP delivers smaller files than PNG while preserving transparency, and smaller files than JPEG at comparable quality. Use it when bandwidth or storage matters and the output stays inside a WebP-aware viewer.

This guide covers exporting to WebP, configuring quality, resizing the output, and saving the result to disk.

Export to WebP#

Export a design block by calling engine.block.export(_:mimeType:options:) with .webp as the MIME type. The call returns a Blob (a Data value) containing the encoded image. The webpQuality field on ExportOptions controls compression — 0.8 is a good starting point for web delivery.

let blob: Blob = try await engine.block.export(
page,
mimeType: .webp,
options: ExportOptions(webpQuality: 0.8),
)

Pass a page returned by engine.scene.getPages(), or any other block ID, to export specific elements.

Export Options#

WebP export reads these fields from ExportOptions:

OptionTypeDefaultDescription
webpQualityFloat1.0Quality from just above 0 to 1.0. 1.0 switches the encoder to lossless mode
targetWidthFloat0Output width in pixels. Used together with targetHeight; 0 disables the override
targetHeightFloat0Output height in pixels. Used together with targetWidth; 0 disables the override

Lossless Compression#

Set webpQuality to 1.0 to switch the encoder to its lossless mode. WebP’s lossless encoding usually produces smaller files than PNG while preserving every pixel.

let losslessBlob = try await engine.block.export(
page,
mimeType: .webp,
options: ExportOptions(webpQuality: 1.0),
)

Values between 0.8 and 0.95 keep visual quality high while shrinking the file substantially. Lower values trade more visible quality for smaller files.

Target Dimensions#

Specify targetWidth and targetHeight together to export at exact dimensions. The output fills the target size while maintaining aspect ratio.

let sizedBlob = try await engine.block.export(
page,
mimeType: .webp,
options: ExportOptions(
webpQuality: 0.85,
targetWidth: 1920,
targetHeight: 1080,
),
)

If the target aspect ratio differs from the block’s aspect ratio, the output extends beyond the target on one axis to preserve proportions.

Save to File System#

The returned Blob is a Data value, so writing it to disk is a single call to write(to:).

let outputURL = FileManager.default.temporaryDirectory.appendingPathComponent("export.webp")
try blob.write(to: outputURL)

Troubleshooting#

File still too large — Lower webpQuality toward 0.50.7, or reduce dimensions with targetWidth and targetHeight. Pure-photographic content compresses well at lower quality settings.

Transparent areas appear opaque — Verify the source page or block has a transparent background fill. WebP preserves alpha when the source block is transparent.

Output looks degraded at high quality — Switch to lossless by setting webpQuality to 1.0. For graphics with sharp edges and text, lossless WebP avoids the smearing that lossy compression can introduce.

API Reference#

MethodDescription
engine.block.export(_:mimeType:options:)Export a block to the specified format
engine.scene.load(from:)Load a scene from a remote URL
engine.scene.getPages()Return all pages in the current scene
ExportOptionsFormat-specific export configuration; WebP reads webpQuality, targetWidth, targetHeight

Next Steps#

  • Export Overview — Compare all available export formats
  • Export to PDF — Generate print-ready PDF documents from your designs
  • Partial Export — Export specific blocks, groups, or page elements instead of entire scenes
  • Export Size Limits — Check device export limits before exporting large designs