From f02e8044540e090a5a43aad0a39d6a392a56c75d Mon Sep 17 00:00:00 2001 From: GTSuya Studio Date: Sun, 29 Mar 2026 14:05:55 -0400 Subject: [PATCH] Add Random SDXL Resolutions node --- README.md | 36 ++++++++++++++++++++++++++++++++++ __init__.py | 1 + gtsuya_nodes.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/README.md b/README.md index 58c5144..30a47a8 100644 --- a/README.md +++ b/README.md @@ -88,10 +88,46 @@ This is a simple node that returns a random file path from a directory. In case To use this node you just have to indicate a directory path where the files you want to randomly select are located. +## Image / Random SDXL Resolution +This node generates a random resolution from the official SDXL format list and returns the corresponding `width` and `height` values. It is useful to automatically vary image dimensions across a batch without manually switching resolutions. To add **Random SDXL Resolution** node: Right-click > Add Node > GtsuyaStudio > Image > Random SDXL Resolution. + +To use this node, choose a generation **mode** from the dropdown and connect a **seed** value for reproducibility. The node will output the selected `width` and `height` integers, which can be wired directly into an **Empty Latent Image** or **KSampler** node. + +### Inputs + +| Parameter | Type | Description | +|-----------|------|-------------| +| `mode` | Dropdown | Filters available resolutions: `All`, `Landscape only`, `Portrait only`, `Square only` | +| `seed` | INT | Random seed for reproducibility. Connect to a global seed node to keep results consistent across your workflow. | + +### Outputs + +| Output | Type | Description | +|--------|------|-------------| +| `width` | INT | Width of the randomly selected resolution | +| `height` | INT | Height of the randomly selected resolution | + +### Available Resolutions + +| Orientation | Width | Height | +|-------------|-------|--------| +| Landscape | 1536 | 640 | +| Landscape | 1344 | 768 | +| Landscape | 1216 | 832 | +| Landscape | 1152 | 896 | +| Square | 1024 | 1024 | +| Portrait | 896 | 1152 | +| Portrait | 832 | 1216 | +| Portrait | 768 | 1344 | +| Portrait | 640 | 1536 | + --- ## Changelog +### Version 1.3.0 +- **New node — Random SDXL Resolution**: Randomly selects a resolution from the official SDXL format list (landscape, portrait, and square) and outputs `width` and `height` integers. Supports mode filtering and seed-based reproducibility. + ### Version 1.2.0 - **Nested wildcards support**: Wildcards can now reference other wildcards recursively - **Wildcard depth control**: New `wildcard_depth` parameter to prevent infinite loops (default: 50, range: 2-256) diff --git a/__init__.py b/__init__.py index ebcd1d6..6ad2c89 100644 --- a/__init__.py +++ b/__init__.py @@ -14,6 +14,7 @@ NODE_CLASS_MAPPINGS = { "Danbooru (ID)": DanbooruID, "Replace Strings": ReplaceStrings, "Random File From Path": RandomFileFromPath, + "Random SDXL Resolutions": RandomSDXLResolutions } __all__ = ['NODE_CLASS_MAPPINGS'] diff --git a/gtsuya_nodes.py b/gtsuya_nodes.py index 1b5e8be..d824820 100644 --- a/gtsuya_nodes.py +++ b/gtsuya_nodes.py @@ -349,6 +349,56 @@ class RandomFileFromPath: return (str(chosen_file),) +# ---------------------------------------------------------------------------------------------------------------------------------------------------# + +SDXL_RESOLUTIONS = { + "Landscape 1536x640": (1536, 640), + "Landscape 1344x768": (1344, 768), + "Landscape 1216x832": (1216, 832), + "Landscape 1152x896": (1152, 896), + "Square 1024x1024": (1024, 1024), + "Portrait 896x1152": (896, 1152), + "Portrait 832x1216": (832, 1216), + "Portrait 768x1344": (768, 1344), + "Portrait 640x1536": (640, 1536), +} + +class RandomSDXLResolutions: + """Select a random SDXL image resolution""" + + CATEGORY = "utils/resolution" + FUNCTION = "get_resolution" + RETURN_TYPES = ("INT", "INT") + RETURN_NAMES = ("width", "height") + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "mode": ( + ["All", "Landscape only", "Portrait only", "Square only"], + {"default": "All"}, + ), + "seed": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFFFFFFFFFFFF}), + } + } + + def get_resolution(self, mode: str, seed: int): + rng = random.Random(seed) + + if mode == "Landscape only": + pool = {k: v for k, v in SDXL_RESOLUTIONS.items() if k.startswith("Landscape")} + elif mode == "Portrait only": + pool = {k: v for k, v in SDXL_RESOLUTIONS.items() if k.startswith("Portrait")} + elif mode == "Square only": + pool = {k: v for k, v in SDXL_RESOLUTIONS.items() if k.startswith("Square")} + else: + pool = SDXL_RESOLUTIONS + + label, (width, height) = rng.choice(list(pool.items())) + print(f"[RandomSDXLResolutions] Selected resolution : {label} → {width} × {height}") + return (width, height) + # ---------------------------------------------------------------------------------------------------------------------------------------------------# # Node display names mapping @@ -361,6 +411,7 @@ NODE_CLASS_MAPPINGS = { "DanbooruID": DanbooruID, "ReplaceStrings": ReplaceStrings, "RandomFileFromPath": RandomFileFromPath, + "RandomSDXLResolutions": RandomSDXLResolutions } NODE_DISPLAY_NAME_MAPPINGS = { @@ -371,4 +422,5 @@ NODE_DISPLAY_NAME_MAPPINGS = { "DanbooruID": "Danbooru (ID)", "ReplaceStrings": "Replace Strings", "RandomFileFromPath": "Random File From Path", + "RandomSDXLResolutions": "Random SDXL Resolutions" }