From dd76824f4b705c86c9f058e9d8ccaddde32f5bfe Mon Sep 17 00:00:00 2001 From: fudosanit Date: Wed, 10 Dec 2025 15:57:07 +0900 Subject: [PATCH] first commit --- README.md | 14 ++++++++ __init__.py | 3 ++ random_resolution_selector.py | 65 +++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 README.md create mode 100644 __init__.py create mode 100644 random_resolution_selector.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..adcdcb7 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# ComfyUI Random Resolution Selector + +[ComfyUI](https://github.com/comfyanonymous/ComfyUI) 向けのカスタムノードです。 +設定された基準解像度(Width/Height)をもとに、**「そのまま」「縦横入れ替え」「正方形」** の3つのパターンから解像度をランダム(または指定順)に決定して出力します。 + +同じプロンプトで「縦長・横長・正方形」の構図をまとめてテスト生成したい場合や、画角のバリエーションをランダムに持たせたい場合に便利です。 + +## インストール方法 + +`ComfyUI/custom_nodes/` ディレクトリに移動し、このリポジトリをクローンしてください。 + +```bash +cd ComfyUI/custom_nodes/ +git clone https://github.com/fudosanit/ComfyUI-Random-Resolution.git \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..0cb5a6e --- /dev/null +++ b/__init__.py @@ -0,0 +1,3 @@ +from .random_resolution_selector import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS + +__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] \ No newline at end of file diff --git a/random_resolution_selector.py b/random_resolution_selector.py new file mode 100644 index 0000000..dcbf075 --- /dev/null +++ b/random_resolution_selector.py @@ -0,0 +1,65 @@ +# random_resolution_selector.py + +import time +import random + +class RandomResolutionSelector: + last_seed = 0 # increment用 + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "height": ("INT", {"default": 896, "min": 1}), + "width": ("INT", {"default": 1152, "min": 1}), + "random_toggle": ("BOOLEAN", {"default": True}), + "seed": ("INT", {"default": 0, "min": 0}), + "seed_behavior": ( + ["fixed", "randomize", "increment"], + { + "default": "randomize", + "label": "生成後の制御" + } + ) + } + } + + RETURN_TYPES = ("INT", "INT", "STRING",) + RETURN_NAMES = ("width", "height", "display",) + FUNCTION = "select" + CATEGORY = "custom/resolution" + + def select(self, height, width, random_toggle, seed, seed_behavior): + # シードの決定方法 + if seed_behavior == "randomize": + seed = random.randint(0, 1_000_000_000) + elif seed_behavior == "increment": + seed = RandomResolutionSelector.last_seed + 1 + RandomResolutionSelector.last_seed = seed + # fixed はそのまま seed を使用 + + if random_toggle: + mode = seed % 3 + if mode == 0: + mode_name = "original" + elif mode == 1: + mode_name = "swapped" + height, width = width, height + else: + mode_name = "square" + size = int((height + width) / 2) + height = width = size + else: + mode_name = "fixed" + + display_text = f"width: {width}, height: {height} (seed: {seed}, mode: {mode_name})" + return (width, height, display_text) + +# ノード登録 +NODE_CLASS_MAPPINGS = { + "RandomResolutionSelector": RandomResolutionSelector +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "RandomResolutionSelector": "Random Resolution Selector" +}