Skip to content

Commit

Permalink
Thumbnail Preview, Random Panel Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Suzie1 committed Dec 26, 2023
1 parent 428dc7d commit b3587eb
Show file tree
Hide file tree
Showing 13 changed files with 1,066 additions and 100 deletions.
10 changes: 9 additions & 1 deletion Patch_Notes.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# 🧩 Comfyroll Custom Nodes - Patch Notes

## v1.51 Dec 26, 2023
- added CR Thumbnail Template
- added CR_Random Panel Code

## v1.50 Dec 25, 2023
- CR Float Range List
- CR Integer Range List

## v1.49 Dec 25, 2023
- added CR Draw Pie
- added CR_RandomShapePattern
- added CR_Random Shape Pattern
- updated CR Random Multiline Values
- updated CR Image Output

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Co-authored by Suzie1 and RockOfFire

Current version: 1.50
Current version: 1.51

# Wiki

Expand Down Expand Up @@ -97,6 +97,7 @@ __👽 Graphics - Template__
* CR Comic Panel Templates
* CR Simple Banner (new 18/12/2023)
* CR Simple Image Compare (new 18/12/2023)
* CR Thumbnail Preview (new 26/12/2023)

__🌁 Graphics - Layout__
* CR Image Panel
Expand Down Expand Up @@ -168,8 +169,9 @@ __🔀 Logic__
__🎲 Random__
* CR Random Hex Color
* CR Random RGB
* CR Random Multiline Values (new 8/12/2023)
* CR Random Multiline Values (updated 26/12/2023)
* CR Random RGB Gradient (new 8/12/2023)
* CR Random Panel Code (new 26/12/2023)

__📦 Other__
* CR Image Output (changed 18/12/2023)
Expand Down
14 changes: 9 additions & 5 deletions live_node_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .animation_nodes.cyclers import *

LIVE_NODE_CLASS_MAPPINGS = {
### Misc Nodes
### Other Nodes
"CR Image Output": CR_ImageOutput,
"CR Integer Multiple": CR_IntegerMultipleOf,
"CR Latent Batch Size": CR_LatentBatchSize,
Expand All @@ -40,7 +40,7 @@
"CR Value": CR_Value,
"CR Conditioning Mixer": CR_ConditioningMixer,
"CR Select Model": CR_SelectModel,
"CR Multiline Text": CR_MultilineText,
"CR Multiline Text": CR_MultilineText,
### List Nodes
"CR Font File List": CR_FontFileList,
"CR Text List": CR_TextList,
Expand Down Expand Up @@ -134,6 +134,7 @@
"CR Simple Banner": CR_SimpleBanner,
"CR Comic Panel Templates": CR_ComicPanelTemplates,
"CR Simple Image Compare": CR_SimpleImageCompare,
"CR Thumbnail Preview": CR_ThumbnailPreview,
### Utils Logic Nodes
"CR Image Input Switch": CR_ImageInputSwitch,
"CR Image Input Switch (4 way)": CR_ImageInputSwitch4way,
Expand Down Expand Up @@ -168,7 +169,8 @@
"CR Random Hex Color": CR_RandomHexColor,
"CR Random RGB": CR_RandomRGB,
"CR Random Multiline Values": CR_RandomMultilineValues,
"CR Random RGB Gradient": CR_RandomRGBGradient,
"CR Random RGB Gradient": CR_RandomRGBGradient,
"CR Random Panel Codes": CR_RandomPanelCodes,
#------------------------------------------------------
### Animation Nodes
# Schedules
Expand Down Expand Up @@ -227,7 +229,7 @@
}

LIVE_NODE_DISPLAY_NAME_MAPPINGS = {
### Misc Nodes
### Other Nodes
"CR Image Output": "💾 CR Image Output",
"CR Integer Multiple": "⚙️ CR Integer Multiple",
"CR Latent Batch Size": "⚙️ CR Latent Batch Size",
Expand Down Expand Up @@ -331,6 +333,7 @@
"CR Simple Banner": "👽 CR Simple Banner",
"CR Comic Panel Templates": "👽 CR Comic Panel Templates",
"CR Simple Image Compare": "👽 CR Simple Image Compare",
"CR Thumbnail Preview": "👽 CR Thumbnail Preview",
### Utils Logic Nodes
"CR Image Input Switch": "🔀 CR Image Input Switch",
"CR Image Input Switch (4 way)": "🔀 CR Image Input Switch (4 way)",
Expand Down Expand Up @@ -365,7 +368,8 @@
"CR Random Hex Color": "🎲 CR Random Hex Color",
"CR Random RGB": "🎲 CR Random RGB",
"CR Random Multiline Values": "🎲 CR Random Multiline Values",
"CR Random RGB Gradient": "🎲 CR Random RGB Gradient",
"CR Random RGB Gradient": "🎲 CR Random RGB Gradient",
"CR Random Panel Codes": "🎲 CR Random Panel Codes",
#------------------------------------------------------
### Animation Nodes
# Schedules
Expand Down
33 changes: 32 additions & 1 deletion nodes/graphics_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# for ComfyUI https://github.com/comfyanonymous/ComfyUI
#---------------------------------------------------------------------------------------------------------------------#

import numpy as np
import torch
import os
import random
from PIL import Image, ImageDraw, ImageFont, ImageOps, ImageEnhance
Expand All @@ -12,6 +14,14 @@
file_list = [f for f in os.listdir(font_dir) if os.path.isfile(os.path.join(font_dir, f)) and f.lower().endswith(".ttf")]


def tensor2pil(image):
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8))


def pil2tensor(image):
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)


def align_text(align, img_height, text_height, text_pos_y, margins):
if align == "center":
text_plot_y = img_height / 2 - text_height / 2 + text_pos_y
Expand Down Expand Up @@ -442,4 +452,25 @@ def random_rgb():
# Format RGB as a string in the format "128,128,128"
rgb_string = "{},{},{}".format(r, g, b)

return rgb_string
return rgb_string


def make_grid_panel(images, max_columns):

# Calculate dimensions for the grid
num_images = len(images)
num_rows = (num_images - 1) // max_columns + 1
combined_width = max(image.width for image in images) * min(max_columns, num_images)
combined_height = max(image.height for image in images) * num_rows

combined_image = Image.new('RGB', (combined_width, combined_height))

x_offset, y_offset = 0, 0 # Initialize offsets
for image in images:
combined_image.paste(image, (x_offset, y_offset))
x_offset += image.width
if x_offset >= max_columns * image.width:
x_offset = 0
y_offset += image.height

return combined_image
2 changes: 1 addition & 1 deletion nodes/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import folder_paths
import typing as tg
import datetime
from io import BytesIO, StringIO
import io
from server import PromptServer, BinaryEventTypes
from PIL import Image
from PIL.PngImagePlugin import PngInfo
Expand Down
69 changes: 56 additions & 13 deletions nodes/nodes_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ class CR_RandomMultilineValues:
@classmethod
def INPUT_TYPES(cls):

types = ["binary", "decimal", "natural", "hexadecimal", "alphabetic", "alphanumeric", "custom"]
types = ["binary", "decimal", "natural", "hexadecimal", "alphabetic", "alphanumeric", "hex color", "custom"]

return {"required": {"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"value_type": (types,),
"rows": ("INT", {"default": 5, "min": 1, "max": 2048}),
"string_length": ("INT", {"default": 5, "min": 1, "max": 2048}),
"string_length": ("INT", {"default": 5, "min": 1, "max": 1024}),
"custom_values": ("STRING", {"multiline": False, "default": "123ABC"}),
"prepend_text": ("STRING", {"multiline": False, "default": ""}),
}
}

Expand All @@ -85,8 +86,10 @@ def INPUT_TYPES(cls):
FUNCTION = "generate"
CATEGORY = icons.get("Comfyroll/Utils/Random")

def generate(self, value_type, rows, string_length, custom_values, seed):
def generate(self, value_type, rows, string_length, custom_values, seed, prepend_text):

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-multiline-values"

# Set the seed
random.seed(seed)

Expand All @@ -97,18 +100,57 @@ def generate(self, value_type, rows, string_length, custom_values, seed):
elif value_type == "natural":
choice_str = '123456789'
elif value_type == "hexadecimal":
choice_str = '0123456789abcdef'
choice_str = '0123456789ABCDEF'
elif value_type == "alphabetic":
choice_str = string.ascii_letters
elif value_type == "alphanumeric":
choice_str = string.ascii_letters + string.digits
elif value_type == "hex color":
choice_str = '0123456789ABCDEF'
elif value_type == "custom":
choice_str = custom_values

multiline_text = '\n'.join([''.join(random.choice(choice_str) for _ in range(string_length)) for _ in range(rows)])

multiline_text = '\n'.join([prepend_text + ''.join(random.choice(choice_str) for _ in range(string_length)) for _ in range(rows)])

return (multiline_text, show_help, )

#---------------------------------------------------------------------------------------------------------------------#
class CR_RandomPanelCodes:

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-multiline-values"

@classmethod
def INPUT_TYPES(cls):

return {"required": {"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"rows": ("INT", {"default": 5, "min": 1, "max": 2048}),
"string_length": ("INT", {"default": 5, "min": 1, "max": 1024}),
"values": ("STRING", {"multiline": False, "default": "123"}),
}
}

RETURN_TYPES = ("STRING", "STRING", )
RETURN_NAMES = ("multiline_text", "show_help", )
FUNCTION = "generate"
CATEGORY = icons.get("Comfyroll/Utils/Random")

def generate(self, rows, string_length, values, seed):

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-panel-codes"

# Set the seed
random.seed(seed)

start_letter = random.choice('HV')
value_range = random.choice(values)

codes = []
for _ in range(rows):
# Generate a random number within the specified range
number = ''.join(random.choice(values) for _ in range(string_length))
# Append the code to the list
codes.append(f"{start_letter}{number}")

multiline_text = '\n'.join(codes)

return (multiline_text, show_help, )

#---------------------------------------------------------------------------------------------------------------------#
Expand All @@ -129,6 +171,8 @@ def INPUT_TYPES(cls):

def generate(self, rows, seed):

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-RGB-gradient"

# Set the seed
random.seed(seed)

Expand All @@ -141,11 +185,9 @@ def generate(self, rows, seed):
upper_bound = min(99, temp + (99 - temp) // (rows - i + 1))
current_value = random.randint(temp, upper_bound)
multiline_text += f'{current_value}:{random.randint(0, 255)},{random.randint(0, 255)},{random.randint(0, 255)}\n'
print(multiline_text)

temp = current_value + 1

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-RGB-gradient"


return (multiline_text, show_help, )

#---------------------------------------------------------------------------------------------------------------------#
Expand All @@ -158,7 +200,8 @@ def generate(self, rows, seed):
"CR Random Hex Color": CR_RandomHexColor,
"CR Random RGB": CR_RandomRGB,
"CR Random Multiline Values": CR_RandomMultilineValues,
"CR Random RGB Gradient": CR_RandomRGBGradient,
"CR Random RGB Gradient": CR_RandomRGBGradient,
"CR Random Panel Codes": CR_RandomPanelCodes,
}
'''

Loading

0 comments on commit b3587eb

Please sign in to comment.