mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2025-12-10 05:15:05 +08:00
Pad node update
This commit is contained in:
parent
26aea1889d
commit
5f16aeec88
@ -3149,9 +3149,11 @@ class ImagePadKJ:
|
|||||||
"extra_padding": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1, }),
|
"extra_padding": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1, }),
|
||||||
"pad_mode": (["edge", "color"],),
|
"pad_mode": (["edge", "color"],),
|
||||||
"color": ("STRING", {"default": "0, 0, 0", "tooltip": "Color as RGB values in range 0-255, separated by commas."}),
|
"color": ("STRING", {"default": "0, 0, 0", "tooltip": "Color as RGB values in range 0-255, separated by commas."}),
|
||||||
}
|
},
|
||||||
, "optional": {
|
"optional": {
|
||||||
"mask": ("MASK", ),
|
"mask": ("MASK", ),
|
||||||
|
"target_width": ("INT", {"default": 512, "min": 0, "max": MAX_RESOLUTION, "step": 1, }),
|
||||||
|
"target_height": ("INT", {"default": 512, "min": 0, "max": MAX_RESOLUTION, "step": 1, }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3161,7 +3163,7 @@ class ImagePadKJ:
|
|||||||
CATEGORY = "KJNodes/image"
|
CATEGORY = "KJNodes/image"
|
||||||
DESCRIPTION = "Pad the input image and optionally mask with the specified padding."
|
DESCRIPTION = "Pad the input image and optionally mask with the specified padding."
|
||||||
|
|
||||||
def pad(self, image, left, right, top, bottom, extra_padding, color, pad_mode, mask=None):
|
def pad(self, image, left, right, top, bottom, extra_padding, color, pad_mode, mask=None, target_width=None, target_height=None):
|
||||||
B, H, W, C = image.shape
|
B, H, W, C = image.shape
|
||||||
|
|
||||||
# Resize masks to image dimensions if necessary
|
# Resize masks to image dimensions if necessary
|
||||||
@ -3177,6 +3179,14 @@ class ImagePadKJ:
|
|||||||
bg_color = torch.tensor(bg_color, dtype=image.dtype, device=image.device)
|
bg_color = torch.tensor(bg_color, dtype=image.dtype, device=image.device)
|
||||||
|
|
||||||
# Calculate padding sizes with extra padding
|
# Calculate padding sizes with extra padding
|
||||||
|
if target_width is not None and target_height is not None:
|
||||||
|
padded_width = target_width
|
||||||
|
padded_height = target_height
|
||||||
|
pad_left = (padded_width - W) // 2
|
||||||
|
pad_right = padded_width - W - pad_left
|
||||||
|
pad_top = (padded_height - H) // 2
|
||||||
|
pad_bottom = padded_height - H - pad_top
|
||||||
|
else:
|
||||||
pad_left = left + extra_padding
|
pad_left = left + extra_padding
|
||||||
pad_right = right + extra_padding
|
pad_right = right + extra_padding
|
||||||
pad_top = top + extra_padding
|
pad_top = top + extra_padding
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user