Search
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
Download
StackBlitz
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 the file system.

Export to JPEG#

Export a design block to JPEG by calling engine.block.export() with mimeType: 'image/jpeg'. Convert the blob to a buffer and write to disk.

blob = await engine.block.export(page, {
mimeType: 'image/jpeg',
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 supports these configuration options:

OptionTypeDefaultDescription
mimeTypestring'image/png'Set to 'image/jpeg' for JPEG
jpegQualitynumber0.9Quality from >0 to 1
targetWidthnumberOutput width in pixels
targetHeightnumberOutput height in pixels

Quality Control#

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

blob = await engine.block.export(page, {
mimeType: 'image/jpeg',
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.

blob = await engine.block.export(page, {
mimeType: 'image/jpeg',
targetWidth: 1920,
targetHeight: 1080
});

Save to File System#

Convert the exported blob to a buffer and write it to disk using Node.js file system APIs.

const buffer = Buffer.from(await blob.arrayBuffer());
writeFileSync(`${OUTPUT_DIR}/${filename}`, buffer);

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.7–0.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(block, options)Export a block to the specified format
engine.scene.loadFromURL(url)Load a scene from a remote URL
engine.block.findByType(type)Find all blocks of a specific type
engine.addDefaultAssetSources()Add default asset sources for resolution
writeFileSync(path, buffer)Write buffer to file system (Node.js)

Next Steps#