-
Notifications
You must be signed in to change notification settings - Fork 5
/
image_nabber.py
36 lines (29 loc) · 1.02 KB
/
image_nabber.py
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
import os
from PIL import Image, ImageOps
import torch
import numpy as np
class ImageNabber:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
# Single file path input
"file_path": ("STRING", {"forceInput": True, "default": "", "dynamicPrompts": False}),
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
FUNCTION = "process"
CATEGORY = "image"
OUTPUT_IS_LIST = (False,)
OUTPUT_NODE = True # Indicates that this node directly outputs to the workflow
def process(cls, file_path):
if not os.path.exists(file_path):
raise FileNotFoundError(f"File '{file_path}' cannot be found.")
# Load the image, ensuring orientation is correct and converting to tensor
i = Image.open(file_path)
i = ImageOps.exif_transpose(i)
image = i.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
return (image, )