diff --git a/__init__.py b/__init__.py index d444188..60acd07 100644 --- a/__init__.py +++ b/__init__.py @@ -101,6 +101,7 @@ NODE_CONFIG = { "VRAM_Debug": {"class": VRAM_Debug, "name": "VRAM Debug"}, "SomethingToString": {"class": SomethingToString, "name": "Something To String"}, "EmptyLatentImagePresets": {"class": EmptyLatentImagePresets, "name": "Empty Latent Image Presets"}, + "EmptyLatentImageCustomPresets": {"class": EmptyLatentImageCustomPresets, "name": "Empty Latent Image Custom Presets"}, "ModelPassThrough": {"class": ModelPassThrough, "name": "ModelPass"}, #audioscheduler stuff "NormalizedAmplitudeToMask": {"class": NormalizedAmplitudeToMask}, diff --git a/custom_dimensions.json b/custom_dimensions.json new file mode 100644 index 0000000..f06408d --- /dev/null +++ b/custom_dimensions.json @@ -0,0 +1,12 @@ +[ + "512x512", + "768x512", + "960x512", + "1024x512", + "1024x576", + "1536x640", + "1344x768", + "1216x832", + "1152x896", + "1024x1024" +] \ No newline at end of file diff --git a/nodes/nodes.py b/nodes/nodes.py index abdde3f..f5c92ee 100644 --- a/nodes/nodes.py +++ b/nodes/nodes.py @@ -708,7 +708,52 @@ class EmptyLatentImagePresets: return (latent, int(width), int(height),) +class EmptyLatentImageCustomPresets: + @classmethod + def INPUT_TYPES(cls): + with open(os.path.join(script_directory, 'custom_dimensions.json')) as f: + dimensions = json.load(f) + return { + "required": { + "dimensions": ( + dimensions, + ), + + "invert": ("BOOLEAN", {"default": False}), + "batch_size": ("INT", { + "default": 1, + "min": 1, + "max": 4096 + }), + }, + } + RETURN_TYPES = ("LATENT", "INT", "INT") + RETURN_NAMES = ("Latent", "Width", "Height") + FUNCTION = "generate" + CATEGORY = "KJNodes" + DESCRIPTION = """ +Generates an empty latent image with the specified dimensions. +The choices are loaded from 'custom_dimensions.json' in the nodes folder. +""" + + def generate(self, dimensions, invert, batch_size): + from nodes import EmptyLatentImage + result = [x.strip() for x in dimensions.split('x')] + + # Remove the aspect ratio part + result[0] = result[0].split('(')[0].strip() + result[1] = result[1].split('(')[0].strip() + + if invert: + width = int(result[1].split(' ')[0]) + height = int(result[0]) + else: + width = int(result[0]) + height = int(result[1].split(' ')[0]) + latent = EmptyLatentImage().generate(width, height, batch_size)[0] + + return (latent, int(width), int(height),) class WidgetToString: @classmethod