Files
JerryOrbachJr-ComfyUI-Rando…/random_size.py
T
2024-01-27 12:16:57 -05:00

27 lines
750 B
Python

import yaml, os, random
module_root_directory = os.path.dirname(os.path.realpath(__file__))
config_file = os.path.join(module_root_directory,'sizes.yaml')
def read_config(item):
with open(config_file, 'r') as file:
return yaml.safe_load(file)[item]
class RandomSize:
CATEGORY = "utils"
@classmethod
def INPUT_TYPES(cls):
return {
"required": {},
}
RETURN_TYPES = ("INT","INT")
RETURN_NAMES = ("width","height")
FUNCTION = "func"
def func(self,size:str):
sizes = read_config('sizes')
rand_obj = random.random.Random()
idx = rand_obj.randint(0, len(sizes))
size = sizes[idx]
x, y = [int(v) for v in size.split('x')]
return (x,y)