Search Docs
Loading...
Skip to content

To JPEG

Export CE.SDK designs to JPEG format—ideal for photographs, social media, and web content where file size matters more than transparency.

5 mins
estimated time
GitHub

JPEG uses lossy compression optimized for photographs and smooth color gradients. Unlike PNG, JPEG does not support transparency—transparent areas render with a solid background.

This guide covers exporting to JPEG, configuring quality and dimensions, and saving exports to disk.

Export to JPEG#

Export a design block by calling engine.block.export(_:mimeType:options:) with .jpeg as the MIME type. The call returns a Blob (a Data value) containing the encoded image.

let blob: Blob = try await engine.block.export(
page,
mimeType: .jpeg,
options: ExportOptions(jpegQuality: 0.9),
)

The jpegQuality parameter accepts values from greater than 0 to 1. Higher values produce better quality at larger file sizes. The default is 0.9.

Export Options#

JPEG export reads these fields from ExportOptions:

OptionTypeDefaultDescription
jpegQualityFloat0.9Quality from >0 to 1
targetWidthFloat0Output width in pixels. Used together with targetHeight; 0 disables the override
targetHeightFloat0Output height in pixels. Used together with targetWidth; 0 disables the override

mimeType is the second argument to engine.block.export(_:mimeType:options:), not a field on ExportOptions.

Quality Control#

Set jpegQuality to 1.0 for maximum quality with minimal compression artifacts. This is useful for archival or print preparation.

let highQualityBlob = try await engine.block.export(
page,
mimeType: .jpeg,
options: ExportOptions(jpegQuality: 1.0),
)

For web delivery, values around 0.8 balance quality and file size effectively.

Target Dimensions#

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

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

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.jpg")
try blob.write(to: outputURL)

When to Use JPEG#

JPEG works well for:

  • Photographs and images with gradual color transitions
  • Social media posts and web content
  • Scenarios where file size matters more than perfect quality

Troubleshooting#

Output looks blurry — Increase jpegQuality toward 1.0, or use PNG for graphics with hard edges.

File size too large — Decrease jpegQuality to 0.70.8, or reduce dimensions with targetWidth and targetHeight.

Unexpected background — JPEG does not support transparency. Use PNG or WebP for transparent content.

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; JPEG reads jpegQuality, targetWidth, targetHeight

Next Steps#

  • Export Overview — Compare all available export formats
  • Export to PDF — Export for print and document workflows
  • Partial Export — Learn how to export specific blocks, groups, and page elements instead of entire scenes using CE.SDK’s programmatic export API.
  • Create Thumbnail — Generate thumbnail preview images by exporting with target dimensions