-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathimage_to_blob_node.py
More file actions
39 lines (31 loc) · 879 Bytes
/
image_to_blob_node.py
File metadata and controls
39 lines (31 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import io
import torch
import numpy as np
from PIL import Image
class ImageToBlobNode:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
},
}
RETURN_TYPES = ("BYTES",)
FUNCTION = "convert_image_to_blob"
CATEGORY = "RequestNode/Converters"
def convert_image_to_blob(self, image):
# Convert tensor to PIL Image
i = 255. * image.cpu().numpy().squeeze()
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
# Save image to a byte buffer
buffer = io.BytesIO()
img.save(buffer, format="PNG")
return (buffer.getvalue(),)
NODE_CLASS_MAPPINGS = {
"ImageToBlobNode": ImageToBlobNode
}
NODE_DISPLAY_NAME_MAPPINGS = {
"ImageToBlobNode": "Image to Blob Node"
}