Search
Loading...
Skip to content

Compress

Compression reduces file sizes during export while maintaining visual quality. With CE.SDK you can fine-tune compression settings for both images and videos, allowing your app to manage performance, quality, and storage efficiency.

Compress example showing CE.SDK with export options

10 mins
estimated time
Download
StackBlitz
GitHub

Image compression reduces file sizes while maintaining acceptable visual quality. CE.SDK supports format-specific compression controls: lossless compression for PNG, lossy quality settings for JPEG, and both modes for WebP. The example includes a navigation bar dropdown menu with export options for comparing different formats and compression levels.

This guide covers exporting with compression settings, configuring quality levels, controlling output dimensions, and video compression options.

Compression Options by Format#

To compress assets, use engine.block.export with format-specific options. Each format supports different parameters for balancing speed, file size, and quality.

FormatParameterTypeEffectDefault
PNGpngCompressionLevel0–9Higher = smaller, slower (lossless)5
JPEGjpegQuality0.0–1.0Lower = smaller, lower quality0.9
WebPwebpQuality0.0–1.01.0 = lossless, below 1.0 = lossy1.0
MP4videoBitrate, audioBitratebits/secHigher = larger, higher quality0 (auto)

Export with Compression#

Call engine.block.export() with format-specific compression options. Each format uses different parameters to control file size and quality.

PNG Compression#

PNG uses lossless compression controlled by pngCompressionLevel (0-9). Higher values produce smaller files but take longer to encode. Quality remains identical at all levels.

// PNG uses lossless compression - level 0-9
// Higher levels = smaller files, slower encoding
// Quality is identical at all levels
const exportPngLevel9 = async () => {
const blob = await engine.block.export(page, {
mimeType: 'image/png',
pngCompressionLevel: 9
});
downloadBlob(blob, 'export-png-level9.png');
cesdk.ui.showNotification({
message: `PNG Level 9: ${(blob.size / 1024).toFixed(0)} KB`,
type: 'success'
});
};

Use level 5-6 for balanced results, or level 9 when file size is critical and encoding time is acceptable.

JPEG Quality#

JPEG uses lossy compression controlled by jpegQuality (0-1). Lower values produce smaller files with more visible artifacts.

// JPEG uses lossy compression - quality 0-1
// Lower values = smaller files, more artifacts
const exportJpeg90 = async () => {
const blob = await engine.block.export(page, {
mimeType: 'image/jpeg',
jpegQuality: 0.9
});
downloadBlob(blob, 'export-jpeg-90.jpg');
cesdk.ui.showNotification({
message: `JPEG 90%: ${(blob.size / 1024).toFixed(0)} KB`,
type: 'success'
});
};

Quality 0.8 provides a good balance for web delivery. Use 0.9+ for archival or print workflows.

WebP Quality#

WebP supports both lossless and lossy modes via webpQuality (0-1). At 1.0, WebP uses lossless encoding. Values below 1.0 enable lossy compression.

// WebP supports both lossless (1.0) and lossy (<1.0) modes
// Typically 20-30% smaller than JPEG at equivalent quality
const exportWebp90 = async () => {
const blob = await engine.block.export(page, {
mimeType: 'image/webp',
webpQuality: 0.9
});
downloadBlob(blob, 'export-webp-90.webp');
cesdk.ui.showNotification({
message: `WebP 90%: ${(blob.size / 1024).toFixed(0)} KB`,
type: 'success'
});
};

WebP typically produces 20-30% smaller files than JPEG at equivalent quality, with optional transparency support.

Target Dimensions#

Use targetWidth and targetHeight together to export at specific dimensions. The block renders large enough to fill the target size while maintaining aspect ratio.

// Combine compression with dimension scaling
// Useful for creating thumbnails or social media previews
const exportScaled = async () => {
const blob = await engine.block.export(page, {
mimeType: 'image/png',
pngCompressionLevel: 6,
targetWidth: 1200,
targetHeight: 630
});
downloadBlob(blob, 'export-scaled-1200x630.png');
cesdk.ui.showNotification({
message: `Scaled 1200×630: ${(blob.size / 1024).toFixed(0)} KB`,
type: 'success'
});
};

Combining dimension scaling with compression produces smaller files suitable for specific platforms like social media thumbnails.

The example demonstrates configuring the CE.SDK navigation bar with a dropdown menu containing all export options. This approach integrates naturally with the editor UI.

// Configure navigation bar with export dropdown
cesdk.ui.setNavigationBarOrder([
'ly.img.back.navigationBar',
'ly.img.undoRedo.navigationBar',
'ly.img.spacer',
'ly.img.zoom.navigationBar',
// Actions dropdown with all export options
{
id: 'ly.img.actions.navigationBar',
children: [
// PNG exports
{
id: 'ly.img.action.navigationBar',
key: 'export-png-9',
label: 'PNG (Level 9 - Smallest)',
icon: '@imgly/Save',
onClick: exportPngLevel9
},
{
id: 'ly.img.action.navigationBar',
key: 'export-png-5',
label: 'PNG (Level 5 - Balanced)',
icon: '@imgly/Save',
onClick: exportPngLevel5
},
// JPEG exports
{
id: 'ly.img.action.navigationBar',
key: 'export-jpeg-90',
label: 'JPEG (90% Quality)',
icon: '@imgly/Save',
onClick: exportJpeg90
},
{
id: 'ly.img.action.navigationBar',
key: 'export-jpeg-60',
label: 'JPEG (60% Quality)',
icon: '@imgly/Save',
onClick: exportJpeg60
},
// WebP exports
{
id: 'ly.img.action.navigationBar',
key: 'export-webp-90',
label: 'WebP (90% Quality)',
icon: '@imgly/Save',
onClick: exportWebp90
},
{
id: 'ly.img.action.navigationBar',
key: 'export-webp-60',
label: 'WebP (60% Quality)',
icon: '@imgly/Save',
onClick: exportWebp60
},
// Scaled export
{
id: 'ly.img.action.navigationBar',
key: 'export-scaled',
label: 'Scaled (1200×630)',
icon: '@imgly/Save',
onClick: exportScaled
},
// Video exports
{
id: 'ly.img.action.navigationBar',
key: 'export-video-web',
label: 'Video 720p (2 Mbps)',
icon: '@imgly/Video',
onClick: exportVideoWeb
},
{
id: 'ly.img.action.navigationBar',
key: 'export-video-hd',
label: 'Video 1080p (8 Mbps)',
icon: '@imgly/Video',
onClick: exportVideoHD
}
]
}
]);

Each menu item triggers an export with specific compression options and displays the resulting file size via a notification.

Compress Videos#

To compress video, use the VideoExportOptions structure in the export workflow. You can specify:

  • Bitrate: Mbps for video, kbps for audio
  • Frame rate: fps (frames per second)
  • H.264 profile: Compatibility and feature level
  • Target resolution: Output dimensions in pixels

The example includes video export options in the dropdown menu. CE.SDK automatically displays a progress modal during video encoding.

// Video export with web-optimized bitrate (720p, 2 Mbps)
const exportVideoWeb = async () => {
const blob = await engine.block.exportVideo(page, {
mimeType: 'video/mp4',
videoBitrate: 2_000_000,
audioBitrate: 128_000,
framerate: 30,
targetWidth: 1280,
targetHeight: 720
});
downloadBlob(blob, 'export-web-720p.mp4');
cesdk.ui.showNotification({
message: `Video 720p: ${(blob.size / (1024 * 1024)).toFixed(1)} MB`,
type: 'success'
});
};
// Video export with HD bitrate (1080p, 8 Mbps)
const exportVideoHD = async () => {
const blob = await engine.block.exportVideo(page, {
mimeType: 'video/mp4',
videoBitrate: 8_000_000,
audioBitrate: 192_000,
framerate: 30,
targetWidth: 1920,
targetHeight: 1080
});
downloadBlob(blob, 'export-hd-1080p.mp4');
cesdk.ui.showNotification({
message: `Video 1080p: ${(blob.size / (1024 * 1024)).toFixed(1)} MB`,
type: 'success'
});
};

Choose Bitrate Values#

Adjust bitrate according to your use case:

  • Web/social media clips: 1–2 Mbps
  • Downloadable HD video: 8–12 Mbps
  • Automatic optimization: Set videoBitrate to 0 to let CE.SDK choose based on resolution and frame rate

H.264 Profile Selection#

The H.264 profile and level determine encoder compatibility and features:

  • Baseline: Mobile-friendly playback
  • Main: Standard HD
  • High: Highest quality (desktop/professional workflows)

Performance and Trade-Offs#

Higher compression produces smaller files but has trade-offs:

  • Slower export speeds with higher compression levels
  • JPEG and WebP are faster but can introduce visible artifacts (blurring, color banding)
  • Video exports are resource-consuming and depend on device CPU/GPU performance

Check Export Limits#

The EditorAPI provides options to check available export limits before encoding:

const maxSize = engine.editor.getMaxExportSize();
const availableMemory = engine.editor.getAvailableMemory();
console.log("Max export size:", maxSize, "Memory:", availableMemory);

Real-World Compression Comparison (1080×1080)#

FormatSettingAvg. File SizeEncode TimePSNRNotes
PNGLevel 0~1,450 KB~44 ms∞ (lossless)Fastest, largest
PNGLevel 5~1,260 KB~61 msBalanced speed and size
PNGLevel 9~1,080 KB~88 msSmallest, slowest
JPEGQuality 95~640 KB~24 ms43 dBNear-lossless
JPEGQuality 80~420 KB~20 ms39 dBGood default for photos
JPEGQuality 60~290 KB~17 ms35 dBSome artifacts visible
WebPQuality 95~510 KB~27 ms44 dBSmaller than JPEG
WebPQuality 80~350 KB~23 ms39 dBGood web balance
WebPLossless~830 KB~33 msSmaller than PNG, keeps alpha

PSNR > 40 dB ≈ visually lossless; 30–35 dB shows mild artifacts.

Key Takeaways:

  • WebP achieves 70–85% smaller files than PNG with high quality around 0.8
  • JPEG performs well for photographs; use 0.8–0.9 for web/print, 0.6 for compact exports
  • PNG is essential for transparency; higher levels reduce size modestly at the cost of speed

Practical Presets#

Use CaseFormatSettingsNotes
Web/Social SharingJPEG/WebPjpegQuality: 0.8Balanced quality and size
Transparent AssetsPNG/WebPpngCompressionLevel: 6Maintains transparency
Print/ArchivalPNGpngCompressionLevel: 9Best fidelity, large files
Video for WebMP4videoBitrate: 2_000_000Smooth playback, small file
Video HD DownloadMP4videoBitrate: 8_000_000Full HD quality

Troubleshooting#

IssueSolution
File size not reducedUse the correct option name (jpegQuality, webpQuality)
JPEG quality too lowRaise quality to 0.9 or switch to PNG/WebP lossless
Slow exportLower the compression level—PNG level 5–6 is a good target
Video not compressingSet videoBitrate to a reasonable non-zero value

API Reference#

MethodDescription
engine.block.export(blockId, options)Export a block with compression and format options
engine.block.exportVideo(blockId, options)Export a video with compression settings
engine.editor.getMaxExportSize()Get maximum export dimensions
engine.editor.getAvailableMemory()Get available memory for export

Next Steps#