LayerStyle

2167
By chflame
Updated 15 days ago
View on GitHub →See Common Issues →

A set of nodes for ComfyUI that can composite layer and mask to achieve Photoshop like functionality.

Available Nodes

LayerUtility: ImageMaskScaleAsV2

Documentation for LayerUtility: ImageMaskScaleAsV2 Node

Overview

The LayerUtility: ImageMaskScaleAsV2 node is part of the ComfyUI project, specifically under the LayerUtility category. This node is designed to facilitate the scaling and resizing of images and masks, ensuring they conform to the dimensions of a reference image or tensor. This utility proves useful in various scenarios where consistent image and mask sizes are required, particularly within layered image compositions.

Functionality

The node performs the following primary functions:

  • Scales images and masks to match the dimensions of a given reference image or tensor.
  • Supports different resizing and fitting methods to maintain image quality and consistency.
  • Provides options to set a background color during resizing operations.

Inputs

The LayerUtility: ImageMaskScaleAsV2 node accepts multiple inputs to customize its operation. Inputs are categorized as either required or optional:

Required Inputs

  • scale_as: A reference image or tensor indicating the target dimensions that images and masks should be scaled to. This input determines the final size of processed outputs.

  • fit: Specifies how the image should fit within the target dimensions. Options include:

    • letterbox: Adds padding while preserving the image's aspect ratio.
    • crop: Cuts the image to match the aspect ratio, potentially removing parts of it.
    • fill: Stretches or compresses the image to fit the dimensions exactly.
  • method: Determines the resampling method to be used. Options consist of:

    • lanczos
    • bicubic
    • hamming
    • bilinear
    • box
    • nearest
  • background_color: A string input representing the color to be used as a background during resizing, specified in hexadecimal format (e.g., "#FFFFFF" for white).

Optional Inputs

  • image: A collection of images to be resized. If no images are provided, only masks will be processed.

  • mask: A collection of masks to be resized. If no masks are provided, only images will be processed.

Outputs

The node produces several outputs:

  • image: The resized images, matching the dimensions of the reference input.
  • mask: The resized masks, matching the dimensions of the reference input.
  • original_size: A list containing the original width and height of the images or masks before resizing.
  • width: The width of the output images or masks.
  • height: The height of the output images or masks.

Usage in ComfyUI Workflows

In ComfyUI workflows, the LayerUtility: ImageMaskScaleAsV2 node is utilized to ensure images and masks are uniformly scaled. This consistent resizing is crucial in operations that involve compositing images with precise layering, where uniformity in dimensions is required for seamless integration. Typical uses include:

  • Preparing images for input to classification or object detection models that require fixed-size inputs.
  • Compositing multiple images and masks into a single image with predetermined dimensions, often used in creative image editing and automated art generation.

Special Features and Considerations

  • Background Color Customization: By allowing users to specify a background color, this node provides additional customization for scenarios where padding is added to fit images.

  • Flexible Fitting Methods: The node supports diverse fitting and resampling methods, enabling users to balance speed and quality, depending on the specific requirements of their project.

  • Error Handling and Logging: The node includes logging mechanisms to inform users when images or masks are successfully processed or if any issues arise, aiding in debugging and workflow validation.

  • Modularity: The node can be used in isolation or as part of a larger workflow, making it a versatile tool within the ComfyUI suite for image manipulation tasks.