renamed Condotionig.py -> Conditioning.py moved modded nodes from StandardInputs -> Parent folder (Modded)
111 lines
3.1 KiB
Python
111 lines
3.1 KiB
Python
import math
|
|
from comfy.utils import common_upscale
|
|
|
|
from ...components.fields import Field
|
|
from ...components.sizes import get_image_size, scale_methods
|
|
from ...components.tree import TREE_IMAGES
|
|
|
|
|
|
|
|
class ImageScale_Ratio:
|
|
scale_methods = scale_methods
|
|
crop_methods = ["disabled", "center"]
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"image": Field.image(),
|
|
"upscale_by": Field.float(),
|
|
"upscale_method": Field.combo(cls.scale_methods),
|
|
"crop": Field.combo(cls.crop_methods)
|
|
}
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "upscale"
|
|
|
|
CATEGORY = TREE_IMAGES
|
|
|
|
def upscale(self, image, upscale_method, upscale_by, crop):
|
|
size = get_image_size(image)
|
|
|
|
width_B = int(size[0])
|
|
height_B = int(size[1])
|
|
|
|
samples = image.movedim(-1, 1)
|
|
|
|
height = math.ceil(height_B * upscale_by)
|
|
width = math.ceil(width_B * upscale_by)
|
|
cls = common_upscale(samples, width, height, upscale_method, crop)
|
|
cls = cls.movedim(1, -1)
|
|
return (cls,)
|
|
|
|
|
|
class ImageScale_Side:
|
|
scale_methods = scale_methods
|
|
crop_methods = ["disabled", "center"]
|
|
|
|
def __init__(self) -> None:
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"image": Field.image(),
|
|
"side_length": Field.int(),
|
|
"side": Field.combo(["Longest", "Shortest", "Width", "Height"]),
|
|
"upscale_method": Field.combo(cls.scale_methods),
|
|
"crop": Field.combo(cls.crop_methods)
|
|
}
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "upscale"
|
|
|
|
CATEGORY = TREE_IMAGES
|
|
|
|
def upscale(self, image, upscale_method, side_length: int, side: str, crop):
|
|
samples = image.movedim(-1, 1)
|
|
|
|
size = get_image_size(image)
|
|
|
|
width_B = int(size[0])
|
|
height_B = int(size[1])
|
|
|
|
width = width_B
|
|
height = height_B
|
|
|
|
def determineSide(_side: str) -> tuple[int, int]:
|
|
width, height = 0, 0
|
|
if _side == "Width":
|
|
heigh_ratio = height_B / width_B
|
|
width = side_length
|
|
height = heigh_ratio * width
|
|
elif _side == "Height":
|
|
width_ratio = width_B / height_B
|
|
height = side_length
|
|
width = width_ratio * height
|
|
return width, height
|
|
|
|
if side == "Longest":
|
|
if width > height:
|
|
width, height = determineSide("Width")
|
|
else:
|
|
width, height = determineSide("Height")
|
|
elif side == "Shortest":
|
|
if width < height:
|
|
width, height = determineSide("Width")
|
|
else:
|
|
width, height = determineSide("Height")
|
|
else:
|
|
width, height = determineSide(side)
|
|
|
|
width = math.ceil(width)
|
|
height = math.ceil(height)
|
|
|
|
cls = common_upscale(samples, width, height, upscale_method, crop)
|
|
cls = cls.movedim(1, -1)
|
|
return (cls,)
|