Export design blocks with specific colors masked to transparency, while generating separate alpha mask files for print workflows and automated processing.
When exporting, CE.SDK can remove specific RGB colors by replacing matching pixels with transparency. The export generates two files: the masked image with transparent areas and an alpha mask showing removed pixels.
Color mask exports work through exact RGB color matching—pixels that precisely match your specified color values (0.0-1.0 range) are removed. This is useful for print workflows (removing registration marks), batch processing (converting background colors to transparency), or generating alpha masks for compositing pipelines.
Exporting with Color Masks#
We export blocks with color masking using the exportWithColorMask method. This method removes specific RGB colors from the rendered output and generates both a masked image and an alpha mask.
// Export with red color masked - removes registration marksconst [maskedImage1, alphaMask1] = await engine.block.exportWithColorMask( page, 1.0, // Red component (0.0-1.0) 0.0, // Green component 0.0, // Blue component (RGB: pure red) { mimeType: 'image/png' });The method accepts the block to export, three RGB color components (0.0-1.0 range), and optional export options like MIME type. This example uses pure red (1.0, 0.0, 0.0) to identify and remove registration marks from the design.
The export operation returns a Promise that resolves to an array containing two Blobs. The first Blob is the masked image with transparency applied where the specified color was found. The second Blob is the alpha mask—a black and white image showing which pixels were removed (black) and which remained (white).
We then convert both Blobs to buffers and save them to the file system using Node.js writeFileSync().
Specifying RGB Color Values#
RGB color components in CE.SDK use floating-point values from 0.0 to 1.0, not the 0-255 integer values common in design tools:
- Pure red:
(1.0, 0.0, 0.0)- Common for registration marks - Pure magenta:
(1.0, 0.0, 1.0)- Distinctive marker color - Pure cyan:
(0.0, 1.0, 1.0)- Alternative marker color - Pure yellow:
(1.0, 1.0, 0.0)- Useful for exclusion zones
When converting from standard 0-255 RGB values, divide each component by 255. For example, RGB(255, 128, 0) becomes (1.0, 0.502, 0.0).
How to Export with Color Masks#
We convert the exported Blobs to buffers and save both the masked image and alpha mask files to the file system. This allows you to use the files in automated workflows or send them to print services.
// Export with red color masked - removes registration marksconst [maskedImage1, alphaMask1] = await engine.block.exportWithColorMask( page, 1.0, // Red component (0.0-1.0) 0.0, // Green component 0.0, // Blue component (RGB: pure red) { mimeType: 'image/png' });
// Save both files to the file systemconst buffer1 = Buffer.from(await maskedImage1.arrayBuffer());writeFileSync(`${outputDir}/example1-masked.png`, buffer1);const maskBuffer1 = Buffer.from(await alphaMask1.arrayBuffer());writeFileSync(`${outputDir}/example1-mask.png`, maskBuffer1);The masked image is print-ready with the specified color removed. The alpha mask shows exactly where pixels were removed, useful for verification or compositing in external applications.
API Reference#
| Method | Description |
|---|---|
engine.block.exportWithColorMask() | Exports a block with specific RGB color removed, generating masked image and alpha mask |
engine.block.export() | Exports a block without color masking |
engine.scene.getCurrentPage() | Gets the currently active page in the scene |
engine.block.create() | Creates a new block of the specified type |
engine.block.createFill() | Creates a fill definition for blocks |
engine.block.setColor() | Sets the color value for a fill |