@@ -1166,3 +1166,30 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
11661166 image_dto = context .images .save (image = cropped_image )
11671167 return ImageOutput .build (image_dto )
11681168
1169+
1170+ @invocation (
1171+ "paste_image_into_bounding_box" ,
1172+ title = "Paste Image into Bounding Box" ,
1173+ category = "image" ,
1174+ version = "1.0.0" ,
1175+ tags = ["image" , "crop" ],
1176+ )
1177+ class PasteImageIntoBoundingBoxInvocation (BaseInvocation , WithMetadata , WithBoard ):
1178+ """Paste the source image into the target image at the given bounding box.
1179+
1180+ The source image must be the same size as the bounding box, and the bounding box must fit within the target image."""
1181+
1182+ source_image : ImageField = InputField (description = "The image to paste" )
1183+ target_image : ImageField = InputField (description = "The image to paste into" )
1184+ bounding_box : BoundingBoxField = InputField (description = "The bounding box to paste the image into" )
1185+
1186+ def invoke (self , context : InvocationContext ) -> ImageOutput :
1187+ source_image = context .images .get_pil (self .source_image .image_name , mode = "RGBA" )
1188+ target_image = context .images .get_pil (self .target_image .image_name , mode = "RGBA" )
1189+
1190+ bounding_box = self .bounding_box .tuple ()
1191+
1192+ target_image .paste (source_image , bounding_box , source_image )
1193+
1194+ image_dto = context .images .save (image = target_image )
1195+ return ImageOutput .build (image_dto )
0 commit comments