forked from filliptm/ComfyUI_Fill-Nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fl_image_dimension_display.py
39 lines (32 loc) · 1.24 KB
/
fl_image_dimension_display.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
37
38
39
import torch
from PIL import Image
class FL_ImageDimensionDisplay:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE", {}),
}
}
RETURN_TYPES = ("STRING",)
FUNCTION = "display_dimensions"
CATEGORY = "🏵️Fill Nodes"
def display_dimensions(self, image):
# Check the number of dimensions in the image tensor to correctly unpack the dimensions
if isinstance(image, torch.Tensor):
if image.dim() == 4: # Batch dimension is present
_, height, width, _, = image.shape
elif image.dim() == 3: # No batch dimension, single image
_, height, width = image.shape
else:
return ("Unsupported tensor format",)
elif isinstance(image, Image.Image):
width, height = image.size
else:
return ("Unsupported image format",)
# Correctly assign width and height
dimensions = f"Width: {width}, Height: {height}"
# Display dimensions in the UI. This might need to be adapted.
print(dimensions)
# Return the dimensions as a string.
return (dimensions,)