Search
Loading...
Skip to content

Create Thumbnail

Generate thumbnail preview images from CE.SDK scenes by exporting with target dimensions for galleries and design management.

5 mins
estimated time
Download
StackBlitz
GitHub

Thumbnails provide visual previews of designs without loading the full editor. Use engine.block.export() with targetWidth and targetHeight options to scale content while maintaining aspect ratio. Supported formats include PNG, JPEG, and WebP.

This guide covers exporting thumbnails at specific dimensions, choosing formats, optimizing quality and file size, and saving thumbnails to the file system.

Export a Thumbnail#

Call engine.block.export() with target dimensions to create a scaled thumbnail. Both targetWidth and targetHeight must be set together for scaling to work.

const blob = await engine.block.export(page, {
mimeType: 'image/jpeg',
targetWidth: 150,
targetHeight: 150,
jpegQuality: 0.8
});

The block renders large enough to fill the target size while maintaining aspect ratio. If aspect ratios differ, the output extends beyond the target on one axis.

Choose Thumbnail Format#

Select the format via the mimeType option based on your needs:

  • 'image/jpeg' — Smaller files, good for photos, no transparency
  • 'image/png' — Lossless quality, supports transparency
  • 'image/webp' — Best compression, modern browsers only

JPEG Thumbnails#

JPEG works well for photographic content. Control file size with jpegQuality (0-1, default 0.9). Values between 0.75-0.85 balance quality and size for thumbnails.

const blob = await engine.block.export(page, {
mimeType: 'image/jpeg',
targetWidth: 400,
targetHeight: 300,
jpegQuality: 0.85
});

PNG Thumbnails#

PNG provides lossless quality with transparency support. Control encoding speed vs. file size with pngCompressionLevel (0-9, default 5).

const blob = await engine.block.export(page, {
mimeType: 'image/png',
targetWidth: 400,
targetHeight: 300,
pngCompressionLevel: 6
});

WebP Thumbnails#

WebP offers the best compression for modern browsers. Control quality with webpQuality (0-1, default 1.0 for lossless).

const blob = await engine.block.export(page, {
mimeType: 'image/webp',
targetWidth: 400,
targetHeight: 300,
webpQuality: 0.8
});

Common Thumbnail Sizes#

Standard sizes for different use cases:

SizeDimensionsUse Case
Small150×150Grid galleries, file browsers
Medium400×300Preview panels, cards
Large800×600Full previews, detail views

Save to File System#

After exporting, convert the Blob to a Buffer and write to the file system. Create the output directory if it doesn’t exist.

const blob = await engine.block.export(page, {
mimeType: 'image/jpeg',
targetWidth: 400,
targetHeight: 300,
jpegQuality: 0.8
});
const buffer = Buffer.from(await blob.arrayBuffer());
writeFileSync('output/thumbnail.jpg', buffer);

Optimize Thumbnail Quality#

Balance quality with file size using format-specific options:

FormatOptionRangeDefaultNotes
JPEGjpegQuality0-10.9Lower = smaller files, visible artifacts
PNGpngCompressionLevel0-95Higher = smaller files, slower encoding
WebPwebpQuality0-11.01.0 = lossless, lower = lossy compression

For thumbnails, JPEG quality of 0.8 or WebP quality of 0.75-0.85 typically provides good results with small file sizes.

API Reference#

MethodDescription
engine.block.export(blockId, options)Export a block as image with format and dimension options
engine.block.findByType('page')Find all pages in the current scene
engine.dispose()Clean up engine resources when done