Export individual design elements, grouped blocks, or specific pages from your scene server-side using CE.SDK’s headless Node.js engine for automated workflows, batch processing, and backend integrations.
Server-side partial export enables fine-grained control over output generation in headless environments. Export individual images, text blocks, shapes, grouped elements, or specific pages programmatically for asset generation pipelines, automated report creation, or serverless functions. This guide demonstrates how to implement partial exports using CE.SDK’s Node.js engine (@cesdk/node).
This guide covers exporting individual blocks, grouped elements, and pages in Node.js environments, saving outputs to the file system or cloud storage.
Server-side vs Browser Differences#
Engine Initialization#
Server-side uses the @cesdk/node package and CreativeEngine.init() instead of browser’s @cesdk/cesdk-js and CreativeEditorSDK.create(). The Node.js engine runs headlessly without UI components.
// Initialize CE.SDK engine in headless modeconst engine = await CreativeEngine.init({ baseURL: process.env.IMGLY_LOCAL_ASSETS_URL,});Understanding Block Hierarchy and Export#
How Block Hierarchy Affects Exports#
CE.SDK organizes content in a tree structure: Scene → Pages → Groups → Individual Blocks. When you export a block, the export automatically includes all child elements in the hierarchy.
Exporting a page exports every element on that page. Exporting a group exports all blocks within that group. Exporting an individual block (like an image or text) exports only that specific element.
This hierarchical behavior lets you control export scope by choosing which level of the hierarchy to target. Export an image block for a single asset. Export a parent group for a complete layout section.
Export Behavior#
The export API applies several transformations to ensure consistent output. If the exported block itself is rotated, it will be exported without that rotation—the content appears upright in the output file. Any margin set on the block is included in the export bounds. Outside strokes are included for most block types.
Exporting Individual Blocks#
Basic Block Export#
Once we have a scene, we can export individual blocks. Find blocks using findByType(), then export them with specific format options.
// Create first image blockconst imageBlock1 = await engine.block.addImage(imageUri, { size: blockSize,});engine.block.appendChild(page, imageBlock1);
// Export the block as PNGconst individualBlob = await engine.block.export(imageBlock1, { mimeType: 'image/png', pngCompressionLevel: 5,});
// Save individual block exportconst outputDir = './output';if (!existsSync(outputDir)) { mkdirSync(outputDir, { recursive: true });}
const individualBuffer = Buffer.from(await individualBlob.arrayBuffer());writeFileSync(`${outputDir}/individual-block.png`, individualBuffer);console.log('✓ Exported individual block to output/individual-block.png');The mimeType determines the output format. CE.SDK supports PNG, JPEG, WEBP, and PDF. Each format has specific options—PNG uses pngCompressionLevel (0-9), JPEG uses jpegQuality (0-1), and WEBP uses webpQuality (0-1).
PNG supports transparency for UI elements and logos. JPEG suits photographs without transparency needs (replaces transparent areas with solid background). WEBP offers better compression for web delivery. PDF preserves vector data for print workflows. PNG compression (0-9) balances size and encoding speed. JPEG quality (0-1) controls artifacts and file size. WEBP quality (0-1) achieves smallest files with good visual fidelity.
Exporting with Different Options#
Resizing Exports#
Control output dimensions using targetWidth and targetHeight. The engine maintains the block’s aspect ratio while fitting within your specified dimensions. Specify one dimension to auto-calculate the other while preserving aspect ratio. Specify both to fit content within bounds (one dimension may be smaller to maintain proportions). Useful for thumbnails, responsive sizes, or platform constraints.
Checking Export Constraints#
Server environments may have memory limits or maximum texture size constraints. Query these limits before attempting large exports. getMaxExportSize() returns the maximum dimension in pixels of a color mask export and of the layers of a PDF. A PNG, JPEG, WebP, TGA or raw export renders in strips, so only the side limit of its format bounds it. getAvailableMemory() returns available memory in bytes for estimating large export viability. This is critical for memory-constrained deployments, such as serverless functions with the WASM engine (AWS Lambda allows 128 MB to 10 GB), to prevent termination. On AWS Lambda, @cesdk/node runs the WASM engine.
Exporting Pages#
Single Page Export#
Exporting a page captures all content on that page as a single output. The page dimensions determine the export size.
// Export the entire pageconst pageBlob = await engine.block.export(page, { mimeType: 'image/png', pngCompressionLevel: 5,});const pageBuffer = Buffer.from(await pageBlob.arrayBuffer());writeFileSync(`${outputDir}/page-export.png`, pageBuffer);console.log('✓ Exported current page to output/page-export.png');Page exports include all child elements—graphics, text, shapes, and groups. The page background fill is also included. This is useful for generating preview images of multi-page documents or exporting individual pages from a template.
Multi-page Document Export#
For documents with multiple pages, export each page individually to create separate output files.
// Export all pages individually (for multi-page documents)const pages = engine.scene.getPages();for (let i = 0; i < pages.length; i++) { const pageBlob = await engine.block.export(pages[i], { mimeType: 'image/png', }); const pageBuffer = Buffer.from(await pageBlob.arrayBuffer()); writeFileSync(`${outputDir}/page-${i + 1}.png`, pageBuffer);}console.log(`✓ Exported ${pages.length} page(s) individually`);The getPages() method returns all pages in scene order. Export each page with sequential numbering for easy identification. This pattern works for generating page previews, creating print-ready files for each page, or splitting multi-page documents into individual images.
For print workflows, consider exporting pages as PDF to preserve vector information and text quality. For web previews, PNG or WEBP provides good quality at manageable file sizes.
Exporting an Area of a Block#
To export only part of a block, give the exportArea option a rectangle: { x, y, width, height }. The output then contains only that rectangle of the block. This is useful for a detail view, a crop preview, or a tile of a large design. engine.block.exportToStream() takes the same option.
The example exports the top-left quarter of the page at twice its size.
// Export the top-left quarter of the page at twice its sizeconst areaWidth = pageWidth / 2;const areaHeight = pageHeight / 2;const areaBlob = await engine.block.export(page, { mimeType: 'image/png', exportArea: { x: 0, y: 0, width: areaWidth, height: areaHeight }, targetWidth: areaWidth * 2, targetHeight: areaHeight * 2,});const areaBuffer = Buffer.from(await areaBlob.arrayBuffer());writeFileSync(`${outputDir}/page-area-export.png`, areaBuffer);console.log('✓ Exported page area to output/page-area-export.png');- The rectangle uses the block’s design units. (0, 0) is the top-left corner of the block, before rotation. For a scene, the rectangle uses scene coordinates.
targetWidthandtargetHeightscale the rectangle, not the whole block. So you can export a detail at a higher resolution than the whole block gives.- The rectangle can reach outside the block. The export draws it like a full export, with the page fill and the neighboring blocks. The block’s margin and stroke do not make it larger.
- PDF (
application/pdf) does not support an export area. A rectangle with no width or height, or an output smaller than 1 px, makes the export fail. - The export skips most blocks whose drawing stays fully outside the rectangle. It does not wait for them to load, and their load error does not make it fail. Some blocks still draw and load, for example text.
PDF Exports#
Vector Format Output#
PDF exports preserve vector information, making them ideal for print workflows, scalable graphics, or archival purposes.
// Export as PDF to preserve vector informationconst pdfBlob = await engine.block.export(page, { mimeType: 'application/pdf',});const pdfBuffer = Buffer.from(await pdfBlob.arrayBuffer());writeFileSync(`${outputDir}/export.pdf`, pdfBuffer);console.log('✓ Exported page as PDF to output/export.pdf');PDF preserves vector paths, text selectability, and transparency. Produces smaller files than high-resolution PNG for vector-heavy content. Preferred for professional printing (scalability, text editability). Use PNG or WEBP for fixed-dimension web delivery.
Practical Use Cases#
Asset Generation Pipeline#
Generate social media assets from templates by loading a template, modifying text/images programmatically, and exporting different sizes.
const engine = await CreativeEngine.init(config);await engine.scene.load('https://example.com/template.scene');
// Customize contentconst textBlocks = engine.block.findByType('//ly.img.ubq/text');engine.block.setString(textBlocks[0], 'text/text', 'Custom Headline');
// Export multiple sizesconst page = engine.block.findByType('page')[0];
const instagram = await engine.block.export(page, { mimeType: 'image/png', targetWidth: 1080, targetHeight: 1080});
const facebook = await engine.block.export(page, { mimeType: 'image/png', targetWidth: 1200, targetHeight: 630});
const twitter = await engine.block.export(page, { mimeType: 'image/png', targetWidth: 1200, targetHeight: 675});This workflow is ideal for automated social media content generation, email campaign graphics, or personalized marketing materials.
Thumbnail Generation#
Generate thumbnails for preview grids by exporting pages or blocks with small target dimensions.
const pages = engine.scene.getPages();
for (const page of pages) { const thumbnail = await engine.block.export(page, { mimeType: 'image/webp', webpQuality: 0.8, targetWidth: 300, targetHeight: 300 });
// Save or upload thumbnail}Small dimensions and lower quality settings (0.7-0.8) produce small file sizes suitable for fast loading in preview galleries.
API Reference#
| Method | Description |
|---|---|
engine.block.export() |
Export a block with specified format and quality options |
exportArea option of engine.block.export() |
Export only a rectangle of a block, in the block’s design units |
engine.block.findByType() |
Find blocks by type identifier |
engine.block.group() |
Group multiple blocks into a single logical unit |
engine.scene.getPages() |
Get all pages in the current scene |
engine.editor.getMaxExportSize() |
Get maximum export dimension in pixels |
engine.editor.getAvailableMemory() |
Get available engine memory in bytes |