Skip to content

Commit 0c9bc19

Browse files
Add ImageFromBatch.
1 parent cf4910a commit 0c9bc19

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

comfy_extras/nodes_images.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ def repeat(self, image, amount):
4848
s = image.repeat((amount, 1,1,1))
4949
return (s,)
5050

51+
class ImageFromBatch:
52+
@classmethod
53+
def INPUT_TYPES(s):
54+
return {"required": { "image": ("IMAGE",),
55+
"batch_index": ("INT", {"default": 0, "min": 0, "max": 63}),
56+
"length": ("INT", {"default": 1, "min": 1, "max": 64}),
57+
}}
58+
RETURN_TYPES = ("IMAGE",)
59+
FUNCTION = "frombatch"
60+
61+
CATEGORY = "image/batch"
62+
63+
def frombatch(self, image, batch_index, length):
64+
s_in = image
65+
batch_index = min(s_in.shape[0] - 1, batch_index)
66+
length = min(s_in.shape[0] - batch_index, length)
67+
s = s_in[batch_index:batch_index + length].clone()
68+
return (s,)
69+
5170
class SaveAnimatedWEBP:
5271
def __init__(self):
5372
self.output_dir = folder_paths.get_output_directory()
@@ -170,6 +189,7 @@ def save_images(self, images, fps, compress_level, filename_prefix="ComfyUI", pr
170189
NODE_CLASS_MAPPINGS = {
171190
"ImageCrop": ImageCrop,
172191
"RepeatImageBatch": RepeatImageBatch,
192+
"ImageFromBatch": ImageFromBatch,
173193
"SaveAnimatedWEBP": SaveAnimatedWEBP,
174194
"SaveAnimatedPNG": SaveAnimatedPNG,
175195
}

0 commit comments

Comments
 (0)