|
from PIL import Image, ImageOps |
|
from io import BytesIO |
|
import numpy as np |
|
import struct |
|
import comfy.utils |
|
import time |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SaveImageWebsocket: |
|
@classmethod |
|
def INPUT_TYPES(s): |
|
return {"required": |
|
{"images": ("IMAGE", ),} |
|
} |
|
|
|
RETURN_TYPES = () |
|
FUNCTION = "save_images" |
|
|
|
OUTPUT_NODE = True |
|
|
|
CATEGORY = "api/image" |
|
|
|
def save_images(self, images): |
|
pbar = comfy.utils.ProgressBar(images.shape[0]) |
|
step = 0 |
|
for image in images: |
|
i = 255. * image.cpu().numpy() |
|
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) |
|
pbar.update_absolute(step, images.shape[0], ("PNG", img, None)) |
|
step += 1 |
|
|
|
return {} |
|
|
|
@classmethod |
|
def IS_CHANGED(s, images): |
|
return time.time() |
|
|
|
NODE_CLASS_MAPPINGS = { |
|
"SaveImageWebsocket": SaveImageWebsocket, |
|
} |
|
|