fred-dev/comfy_ui_ali
0
1from PIL import Image2import numpy as np3import comfy.utils4import time5 6#You can use this node to save full size images through the websocket, the7#images will be sent in exactly the same format as the image previews: as8#binary images on the websocket with a 8 byte header indicating the type9#of binary message (first 4 bytes) and the image format (next 4 bytes).10 11#Note that no metadata will be put in the images saved with this node.12 13class SaveImageWebsocket:14 @classmethod15 def INPUT_TYPES(s):16 return {"required":17 {"images": ("IMAGE", ),}18 }19 20 RETURN_TYPES = ()21 FUNCTION = "save_images"22 23 OUTPUT_NODE = True24 25 CATEGORY = "api/image"26 27 def save_images(self, images):28 pbar = comfy.utils.ProgressBar(images.shape[0])29 step = 030 for image in images:31 i = 255. * image.cpu().numpy()32 img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))33 pbar.update_absolute(step, images.shape[0], ("PNG", img, None))34 step += 135 36 return {}37 38 @classmethod39 def IS_CHANGED(s, images):40 return time.time()41 42NODE_CLASS_MAPPINGS = {43 "SaveImageWebsocket": SaveImageWebsocket,44}45 