Extensions/comfyui-transparent-png-creator
ComfyUI Extension

comfyui-transparent-png-creator

Create transparent PNG images from RGB + mask input with automatic bounding box cropping. Supports mask inversion and flexible image/mask size mismatch handling.

By CountlessSkies·Created 2 months ago·Updated 2 months ago· 0
CountlessSkies/comfyui-transparent-png-creator
Nodes1
On cloudLocal install
Categoryimage/process
Stars0
Updated2 months ago
Readme

ComfyUI Transparent PNG Creator Custom Node

This custom node takes an RGB image and a mask, and returns an RGBA (transparent) image where the masked area remains opaque, and everything else is transparent. It can also automatically crop/trim the output image to the bounding box of the mask.

Node: Transparent PNG From Mask

Inputs:

  • image: The source image (RGB or RGBA).
  • mask: The mask defining the area to keep (transparency stencil).
  • trim_to_mask (Boolean, default: False): If enabled, crops the output image and mask to the bounding box of the masked region.
  • padding (Integer, default: 10): Bounding box padding in pixels.
  • invert_mask (Boolean, default: False): Inverts the mask before processing.
  • resize_mode (Option, default: scale_mask_to_image): Configures how to handle size mismatches between the image and the mask:
    • scale_mask_to_image: Resizes the mask to match the dimensions of the input image.
    • scale_image_to_mask: Resizes the input image to match the dimensions of the mask.
    • none: Does not scale. Prints a warning and falls back to scaling the mask to prevent workflow crashes.

Outputs:

  • image: The resulting RGBA image tensor.
  • mask: The cropped/adjusted mask tensor.