Add EmptyLatentImageCustomPresets

This commit is contained in:
kijai 2024-09-17 16:08:59 +03:00
parent 7cb775ce40
commit 3dacf166df
3 changed files with 58 additions and 0 deletions

View File

@ -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},

12
custom_dimensions.json Normal file
View File

@ -0,0 +1,12 @@
[
"512x512",
"768x512",
"960x512",
"1024x512",
"1024x576",
"1536x640",
"1344x768",
"1216x832",
"1152x896",
"1024x1024"
]

View File

@ -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