Skip to main content

Mask Image

Controlled node

Overview

The Mask Image node applies a mask to an input image using the Jimp image processing library. This is useful for creating transparency effects, cropping images to specific shapes, or applying alpha channel masks to images.

The node takes a base image and a mask image as inputs. The mask should be a Jimp image object (typically a grayscale image or an image with an alpha channel) that defines the transparency or intensity values to apply to the base image.

Mask Behavior

  • White pixels in the mask (or high alpha values) preserve the original image pixels
  • Black pixels in the mask (or low alpha values) make the corresponding pixels transparent
  • Gray values create partial transparency based on the intensity

Inputs

InputTypeDescriptionDefault
RunEventTriggers the mask application operation-
ImageDataThe base image to apply the mask to. Must be a valid Jimp image object.-
MaskDataThe mask image to apply. Must be a valid Jimp image object (typically grayscale or with alpha channel).-

Outputs

OutputTypeDescription
DoneEventFires when the mask has been successfully applied
OutputDataThe resulting masked image (Jimp object)

Runtime Behavior and Defaults

When the Run event fires, the node applies the mask to the input image using Jimp's mask() method. The operation modifies the alpha channel of the base image based on the luminance or alpha values of the mask image.

If either the image or mask inputs are not valid Jimp objects, the node will output null for the output.

The node does not modify the original image object; it creates a clone before applying the mask (handled by the ImageProcessingNode1To1 base class).

Example Usage

Basic Mask Application

Connect a Read Image node to provide the base image, and another Read Image node (or AI Generate Image node) to provide the mask:

[Read Image] --(image)--> [Mask Image] --(output)--> [Write To Library]
| ^
| |
[Read Image] --(mask)---------+

In this example:

  1. The first Read Image node loads the base image (e.g., a photo)
  2. The second Read Image node loads the mask (e.g., a grayscale circle to create a circular crop effect)
  3. The Mask Image node applies the mask when triggered by the Run event
  4. The result is passed to Write To Library to save the masked image

Creating a Circular Profile Picture

You can use this node with a generated circular mask to create circular profile pictures:

  1. Load a square photo using Read Image
  2. Generate or load a circular mask (white circle on black background) using another Read Image or AI Generate Image
  3. Connect both to the Mask Image node
  4. The output will be the photo with transparent corners, cropped to a circle
Mask Requirements

For best results, ensure your mask image is the same dimensions as your base image. If the mask is a different size, Jimp will position it at the top-left corner (0,0) of the base image.