diff --git a/nodes.py b/nodes.py index c793c42..d325acf 100644 --- a/nodes.py +++ b/nodes.py @@ -1109,6 +1109,8 @@ class ImageConcanate: "direction": ( [ 'right', 'down', + 'left', + 'up', ], { "default": 'right' @@ -1124,6 +1126,10 @@ class ImageConcanate: row = torch.cat((image1, image2), dim=2) elif direction == 'down': row = torch.cat((image1, image2), dim=1) + elif direction == 'left': + row = torch.cat((image2, image1), dim=2) + elif direction == 'up': + row = torch.cat((image2, image1), dim=1) return (row,) class ImageGridComposite2x2: @@ -1172,6 +1178,62 @@ class ImageGridComposite3x3: grid = torch.cat((top_row, mid_row, bottom_row), dim=1) return (grid,) +import random +class ImageBatchTestPattern: + @classmethod + def INPUT_TYPES(s): + return {"required": { + "batch_size": ("INT", {"default": 1,"min": 1, "max": 255, "step": 1}), + "start_from": ("INT", {"default": 1,"min": 1, "max": 255, "step": 1}), + "width": ("INT", {"default": 512,"min": 16, "max": 4096, "step": 1}), + "height": ("INT", {"default": 512,"min": 16, "max": 4096, "step": 1}), + }} + + RETURN_TYPES = ("IMAGE",) + FUNCTION = "generatetestpattern" + CATEGORY = "KJNodes" + + + + def generatetestpattern(self, batch_size, start_from, width, height): + out = [] + # Generate the sequential numbers for each image + numbers = np.arange(batch_size) + + # Create an image for each number + for i, number in enumerate(numbers): + # Create a black image with the number as a random color text + image = Image.new("RGB", (width, height), color=0) + draw = ImageDraw.Draw(image) + + # Draw a border around the image + border_width = 10 + border_color = (255, 255, 255) # white color + border_box = [(border_width, border_width), (width - border_width, height - border_width)] + draw.rectangle(border_box, fill=None, outline=border_color) + + font_size = 255 # Choose the desired font size + font_path = "fonts\\TTNorms-Black.otf" #I don't know why relative path won't work otherwise... + font_path = os.path.join(script_dir, font_path) + + # Generate a random color for the text + color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) + + font = ImageFont.truetype(font_path, font_size) # Replace "path_to_font_file.ttf" with the path to your font file + text_width = font_size + text_height = font_size + text_x = (width - text_width / 2) // 2 + text_y = (height - text_height) // 2 + + draw.text((text_x, text_y), str(number + start_from), font=font, fill=color) + + # Convert the image to a numpy array and normalize the pixel values + image = np.array(image).astype(np.float32) / 255.0 + image = torch.from_numpy(image)[None,] + out.append(image) + + return (torch.cat(out, dim=0),) + NODE_CLASS_MAPPINGS = { "INTConstant": INTConstant, "FloatConstant": FloatConstant, @@ -1197,7 +1259,8 @@ NODE_CLASS_MAPPINGS = { "ReverseImageBatch": ReverseImageBatch, "ImageGridComposite2x2": ImageGridComposite2x2, "ImageGridComposite3x3": ImageGridComposite3x3, - "ImageConcanate": ImageConcanate + "ImageConcanate": ImageConcanate, + "ImageBatchTestPattern": ImageBatchTestPattern, } NODE_DISPLAY_NAME_MAPPINGS = { "INTConstant": "INT Constant", @@ -1223,5 +1286,6 @@ NODE_DISPLAY_NAME_MAPPINGS = { "ReverseImageBatch": "ReverseImageBatch", "ImageGridComposite2x2": "ImageGridComposite2x2", "ImageGridComposite3x3": "ImageGridComposite3x3", - "ImageConcanate": "ImageConcanate" + "ImageConcanate": "ImageConcanate", + "ImageBatchTestPattern": "ImageBatchTestPattern" } \ No newline at end of file