[ImagePad][Added] Copy input size when target_* is 0
This commit is contained in:
@@ -84,7 +84,7 @@ Shows how to use the image downloader node.
|
||||
|
||||
Shows the most common uses of the resize and padding nodes. You can see how various modes and options affects the result and how the different interpolation methods works. It shows how masks and RGBA images are handled.
|
||||
|
||||
[](https://raw.githubusercontent.com/set-soft/ComfyUI-ImageMisc/refs/heads/main/example_workflows/resize.json) :
|
||||
[](https://raw.githubusercontent.com/set-soft/ComfyUI-ImageMisc/refs/heads/main/example_workflows/resize.json)
|
||||
|
||||
|
||||
## 📝 Usage Notes
|
||||
|
||||
+7
-7
@@ -193,11 +193,11 @@
|
||||
- `edge_pixel`: Repeats the outermost line of pixels.
|
||||
- `color`: Fills with the specified solid `color`.
|
||||
- `pillarbox_blur`: Fills with a blurred, desaturated, and dimmed version of the original image, scaled to fit the new dimensions.
|
||||
- `color` (`STRING`): The solid color to use when `pad_mode` is "color". Accepts hex codes, color names, and RGB values.
|
||||
- `color` (`STRING`): The solid color to use when `pad_mode` is "color". Accepts hex codes, color names, and RGB values. This is more flexible than in KJNodes.
|
||||
- `mask` (`MASK`, optional): An optional mask to be padded along with the image.
|
||||
- `target_width` (`INT`, optional): If provided with `target_height`, pads the image to this exact width, centering the original content. This overrides the `left` and `right` inputs.
|
||||
- `target_height` (`INT`, optional): If provided with `target_width`, pads the image to this exact height, centering the original content. This overrides the `top` and `bottom` inputs.
|
||||
- `pad_transparency` (`FLOAT`, optional): Controls the opacity of the padded area in the output mask. 1.0 is fully transparent (no mask), and 0.0 is fully opaque (masked).
|
||||
- `target_width` (`INT`, optional): If provided with `target_height`, pads the image to this exact width, centering the original content. This overrides the `left` and `right` inputs. If you set it to 0 the width of the image is used. Note that you must also connect `target_height`.
|
||||
- `target_height` (`INT`, optional): If provided with `target_width`, pads the image to this exact height, centering the original content. This overrides the `top` and `bottom` inputs. If you set it to 0 the heigth of the image is used. Note that you must also connect `target_width`.
|
||||
- `pad_transparency` (`FLOAT`, optional): Controls the opacity of the padded area in the output mask. 1.0 is fully transparent (no mask), and 0.0 is fully opaque (masked). Not in KJNodes.
|
||||
- **Outputs:**
|
||||
- `images` (`IMAGE`): The padded image tensor.
|
||||
- `masks` (`MASK`): The padded mask tensor.
|
||||
@@ -221,14 +221,14 @@
|
||||
- `pad`, `pad_edge`, `pad_edge_pixel`: Resizes the image to fit within the target dimensions while maintaining aspect ratio, then pads the remaining space to meet the exact target dimensions.
|
||||
- `crop`: Resizes and crops the image to match the target aspect ratio and size.
|
||||
- `pillarbox_blur`: Resizes the image to fit and fills the remaining space with a blurred background.
|
||||
- `pad_color` (`STRING`): The solid color to use for padding when `keep_proportion` is set to `pad`.
|
||||
- `pad_color` (`STRING`): The solid color to use for padding when `keep_proportion` is set to `pad`. Accepts hex codes, color names, and RGB values. This is more flexible than in KJNodes.
|
||||
- `crop_position` (`STRING`): The anchor point (`center`, `top`, `left`, etc.) for `crop` and `pad` operations.
|
||||
- `divisible_by` (`INT`): Ensures the final width and height are multiples of this number, which is often required for models like VAEs.
|
||||
- `mask` (`MASK`, optional): An optional mask to be transformed along with the image.
|
||||
- `device` (`STRING`, optional): The computation device (`cpu` or `gpu`) to use for the operation. Note that `lanczos` is not supported on the GPU.
|
||||
- `get_image_size` (`IMAGE`, optional): If an image is connected, its dimensions will be used as the target width and height, overriding the manual inputs.
|
||||
- `get_image_size` (`IMAGE`, optional): If an image is connected, its dimensions will be used as the target width and height, overriding the manual inputs. Not in KJNodes.
|
||||
- `per_batch` (`INT`, optional): If greater than 0, processes the input batch in smaller sub-batches of this size to reduce memory usage.
|
||||
- `pad_transparency` (`FLOAT`, optional): Controls the opacity of the padded area in the output mask.
|
||||
- `pad_transparency` (`FLOAT`, optional): Controls the opacity of the padded area in the output mask. Not in KJNodes.
|
||||
- **Outputs:**
|
||||
- `IMAGE` (`IMAGE`): The transformed image.
|
||||
- `width` (`INT`): The final width of the output image.
|
||||
|
||||
+15
-1
@@ -77,6 +77,9 @@ PAD_SIZE_OPT = ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1
|
||||
SIZE_OPT = ("INT", {"default": 512, "min": 0, "max": MAX_RESOLUTION, "step": 1})
|
||||
SIZE_OPT_FI = deepcopy(SIZE_OPT)
|
||||
SIZE_OPT_FI[1]["forceInput"] = True
|
||||
SIZE_OPT_FI[1]["tooltip"] = ("Connect both `target` inputs\n"
|
||||
"If 0 the size of the image is used\n"
|
||||
"Overrides left/right/top/bottom")
|
||||
SIZE_OPT[1]["tooltip"] = "Used when no `get_image_size` is provided"
|
||||
PAD_TRANS = ("FLOAT", {
|
||||
"default": 1.0,
|
||||
@@ -726,6 +729,9 @@ class CreateEmptyImage:
|
||||
|
||||
|
||||
# Adapted from KJNodes, credits to Kijai
|
||||
# - When target_width/target_height are 0 we use the image size
|
||||
# - Added control over the transparency of the padded area (pad_transparency)
|
||||
# - Handle RGBA images
|
||||
class ImagePad:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -752,7 +758,8 @@ class ImagePad:
|
||||
RETURN_NAMES = ("images", "masks",)
|
||||
FUNCTION = "pad"
|
||||
CATEGORY = BASE_CATEGORY + "/" + MANIPULATION_CATEGORY
|
||||
DESCRIPTION = "Pad the input image and optionally mask with the specified padding."
|
||||
DESCRIPTION = ("Pad the input image and optionally mask with the specified padding.\n"
|
||||
"The `target_width`/`target_height` overrides left, right, top and bottom.")
|
||||
UNIQUE_NAME = "SET_ImagePad"
|
||||
DISPLAY_NAME = "Pad Image (KJ/SET)"
|
||||
|
||||
@@ -774,6 +781,12 @@ class ImagePad:
|
||||
|
||||
# Calculate padding sizes with extra padding
|
||||
if target_width is not None and target_height is not None:
|
||||
# SET: If any of them is 0 use the current value
|
||||
if target_width == 0:
|
||||
target_width = W
|
||||
if target_height == 0:
|
||||
target_height = H
|
||||
|
||||
if extra_padding > 0:
|
||||
image = upscale(image.movedim(-1, 1), W - extra_padding, H - extra_padding, BEST_UPSCALE).movedim(1, -1)
|
||||
B, H, W, C = image.shape
|
||||
@@ -912,6 +925,7 @@ class ImagePad:
|
||||
# - The color is an string that support various formats
|
||||
# - We can copy the size of a reference image (found in V1, not in V2)
|
||||
# - Removed misleading code to compute padded size when width and/or height was missing
|
||||
# - Added control over the transparency of the padded area
|
||||
class ImageResize:
|
||||
"""
|
||||
A resize and crop node, from ImageResizeKJv2
|
||||
|
||||
Reference in New Issue
Block a user