Export designs to PNG format with lossless quality and optional transparency support.
PNG is a lossless image format that preserves image quality and supports transparency. It’s ideal for designs requiring pixel-perfect fidelity, logos, graphics with transparent backgrounds, and any content where quality cannot be compromised.
This guide covers how to export designs to PNG and configure export options.
Export to PNG#
Use engine.block.export() to export a design block to PNG. The method returns a Blob containing the image data.
// Export a block to PNGconst blob = await engine.block.export(page, { mimeType: 'image/png'});Compression Level#
Control the file size versus export speed tradeoff using pngCompressionLevel. Valid values are 0-9, where higher values produce smaller files but take longer to export. Since PNG is lossless, image quality remains unchanged.
// Export with compression level (0-9)// Higher values produce smaller files but take longer// Quality is not affected since PNG is losslessconst blob = await engine.block.export(page, { mimeType: 'image/png', pngCompressionLevel: 9 // Maximum compression});The default compression level is 5, providing a good balance between file size and export speed.
Target Dimensions#
Resize the output by setting targetWidth and targetHeight. The block scales to fill the target dimensions while maintaining its aspect ratio.
// Export with target dimensions// The block scales to fill the target while maintaining aspect ratioconst blob = await engine.block.export(page, { mimeType: 'image/png', targetWidth: 1920, targetHeight: 1080});Save to Disk#
Convert the exported Blob to a Buffer and write it to the file system.
// Save exported blobs to diskconst outputDir = './output';if (!existsSync(outputDir)) { mkdirSync(outputDir, { recursive: true });}
for (const { name, blob } of blobs) { const buffer = Buffer.from(await blob.arrayBuffer()); writeFileSync(`${outputDir}/${name}`, buffer); console.log(`✓ Exported ${name} (${(blob.size / 1024).toFixed(1)} KB)`);}
console.log(`\n✓ Exported ${blobs.length} PNG file(s) to ${outputDir}/`);Cleanup#
Always dispose the engine when finished to free resources.
// Always dispose the engine to free resourcesengine.dispose();API Reference#
| API | Description |
|---|---|
engine.block.export(block, options) | Exports a block to a Blob with the specified options |
engine.scene.getPages() | Returns an array of all page block IDs |
engine.dispose() | Disposes the engine and frees resources |
Next Steps#
- Conversion Overview - Learn about other export formats
- Export Overview - Understand the full export workflow
- To PDF - Export designs to PDF format