diff --git a/README.md b/README.md index 84608ac..de9ad27 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ value= ![Demo workflow](https://raw.githubusercontent.com/noembryo/ComfyUI-noEmbryo/master/stuff/res_scale1.png) A simple node that outputs the resolution of an image using the dimensions of an input image or some custom user-defined dimensions, using a Scale Factor. +If there is an input image connected, setting either `width` or `height` to 0 will use the other dimension to scale the image (but always multiple of 4). + --- ## Regex Text Chopper ![Demo workflow](https://raw.githubusercontent.com/noembryo/ComfyUI-noEmbryo/master/stuff/regex_text.png) diff --git a/__init__.py b/__init__.py index ba12ae0..fe2db13 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,6 @@ """ @author: noEmbryo -@title: noEmbryo nodes for ComfyUI +@title: noEmbryo nodes @nickname: noEmbryo @description: Some useful nodes for ComfyUI """ diff --git a/nodes.py b/nodes.py index 979c34e..b56fdd8 100644 --- a/nodes.py +++ b/nodes.py @@ -45,7 +45,7 @@ class PromptTermList: # noinspection PyMethodParameters @classmethod def INPUT_TYPES(cls): - list_path = join(LISTS_PATH, "TermList{}.json".format(cls.idx)) + list_path = join(LISTS_PATH, f"TermList{cls.idx}.json") cls.load_data_from_json(list_path) term_list = [i[0] for i in cls.data_labels] return {"required": {"terms": (term_list,), }, @@ -130,7 +130,7 @@ class PromptTermList: text_out = f"{text_out}, {text}" else: text_out = text - return (text_out,) + return (text_out, ) class PromptTermList1(PromptTermList): @@ -186,7 +186,18 @@ class ResolutionScale: def run(self, width, height, scale_factor, image=None): if image is not None: - _, height, width, _ = image.shape + _, img_height, img_width, _ = image.shape + if width == 0: + ratio = img_width / img_height + width = height * ratio + width = int(width / 4) * 4 + elif height == 0: + ratio = img_height / img_width + height = width * ratio + height = int(height / 4) * 4 + else: + width = img_width + height = img_height new_width = int(width * scale_factor) new_height = int(height * scale_factor)