initial commit

This commit is contained in:
Hamilton
2023-11-23 02:20:42 -08:00
commit dc6d608ebf
4 changed files with 97 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
+7
View File
@@ -0,0 +1,7 @@
# Comfy Fit Size
A simple set of nodes for making an image fit within a bounding box
## Author
Hamilton Cline https://hdraws.com
+15
View File
@@ -0,0 +1,15 @@
from .nodes import FitSize, FitSizeFromImage
# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
"FitSizeByMax": FitSize,
"FitSizeFromImage": FitSizeFromImage,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"FitSizeByMax": "Fit Size",
"FitSizeFromImage": "Fit Size From Image",
}
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
+71
View File
@@ -0,0 +1,71 @@
def get_max_size (width, height, max):
aspect_ratio = width / height
fit_width = max
fit_height = max
print(aspect_ratio, fit_width, fit_height, max, width, height)
if aspect_ratio > 1:
fit_height = int(max / aspect_ratio)
else:
fit_width = int(max * aspect_ratio)
return (fit_width, fit_height, aspect_ratio)
def get_image_size(IMAGE) -> tuple[int, int]:
samples = IMAGE.movedim(-1, 1)
size = samples.shape[3], samples.shape[2]
return size
class FitSize:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"original_width": ("INT", {}),
"original_height": ("INT", {}),
"max_size": ("INT", {"default": 768, "step": 8}),
}
}
RETURN_TYPES = ("INT", "INT", "FLOAT")
RETURN_NAMES = ("Fit Width", "Fit Height", "Aspect Ratio")
FUNCTION = "fit_to_size"
CATEGORY = "Fitsize"
def fit_to_size (self, original_width, original_height, max_size):
values = get_max_size(original_width, original_height, max_size)
return values
class FitSizeFromImage:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE",),
"max_size": ("INT", {"default": 768, "step": 8}),
}
}
RETURN_TYPES = ("INT", "INT", "FLOAT")
RETURN_NAMES = ("Fit Width", "Fit Height", "Aspect Ratio")
FUNCTION = "fit_to_size_from_image"
CATEGORY = "Fitsize"
def fit_to_size_from_image (self, image, max_size):
size = get_image_size(image)
values = get_max_size(size[0], size[1], max_size)
return values