@@ -366,29 +366,45 @@ def INPUT_TYPES(s):
366
366
{
367
367
"default" : 'right'
368
368
}),
369
- }}
369
+ },
370
+ "optional" :{
371
+ "image3" : ("IMAGE" ,),
372
+ "image4" : ("IMAGE" ,),
373
+ "image5" : ("IMAGE" ,),
374
+ "image6" : ("IMAGE" ,),
375
+ }
376
+ }
370
377
371
378
RETURN_TYPES = ("IMAGE" ,)
372
379
FUNCTION = "concanate"
373
380
CATEGORY = "utils/image"
374
381
375
- def concanate (self , image1 , image2 , direction ):
376
- if image2 is None :
377
- return (image1 ,)
378
- if image1 .shape [1 :] != image2 .shape [1 :]:
379
- image2 = comfy .utils .common_upscale (
380
- image2 .movedim (- 1 , 1 ), image1 .shape [2 ], image1 .shape [1 ], "bilinear" , "center" ).movedim (1 , - 1 )
381
- if direction == 'right' :
382
- row = torch .cat ((image1 , image2 ), dim = 2 )
383
- elif direction == 'down' :
384
- row = torch .cat ((image1 , image2 ), dim = 1 )
385
- elif direction == 'left' :
386
- row = torch .cat ((image2 , image1 ), dim = 2 )
387
- elif direction == 'up' :
388
- row = torch .cat ((image2 , image1 ), dim = 1 )
382
+ def concanate (self , image1 , image2 , image3 = None , image4 = None , image5 = None , image6 = None , direction = 'right' ):
383
+ images = [image1 , image2 ]
384
+
385
+ # 添加非空的image3-6到列表中
386
+ for img in [image3 , image4 , image5 , image6 ]:
387
+ if img is not None :
388
+ images .append (img )
389
+
390
+ # 如果只有一张图片,直接返回
391
+ if len (images ) == 1 :
392
+ return (images [0 ],)
393
+
394
+ # 调整所有图片的大小为第一张图片的大小
395
+ for i in range (1 , len (images )):
396
+ if images [i ].shape [1 :] != images [0 ].shape [1 :]:
397
+ images [i ] = comfy .utils .common_upscale (
398
+ images [i ].movedim (- 1 , 1 ), images [0 ].shape [2 ], images [0 ].shape [1 ], "bilinear" , "center" ).movedim (1 , - 1 )
399
+
400
+ # 根据方向拼接图片
401
+ if direction in ['right' , 'left' ]:
402
+ row = torch .cat (images if direction == 'right' else [i for i in reversed (images )], dim = 2 )
403
+ elif direction in ['down' , 'up' ]:
404
+ row = torch .cat (images if direction == 'down' else [i for i in reversed (images )], dim = 1 )
405
+
389
406
return (row ,)
390
407
391
-
392
408
class SplitMask :
393
409
394
410
@classmethod
0 commit comments