mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2025-12-09 04:44:30 +08:00
Some string nodes
This commit is contained in:
parent
bdc5a71e8a
commit
c27b0047ff
53
nodes.py
53
nodes.py
@ -11,6 +11,7 @@ from PIL import ImageFilter, Image, ImageDraw, ImageFont
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
import io
|
||||||
import random
|
import random
|
||||||
import math
|
import math
|
||||||
|
|
||||||
@ -66,6 +67,47 @@ class StringConstant:
|
|||||||
def passtring(self, string):
|
def passtring(self, string):
|
||||||
return (string, )
|
return (string, )
|
||||||
|
|
||||||
|
class StringConstantMultiline:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(cls):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"string": ("STRING", {"default": "", "multiline": True}),
|
||||||
|
"strip_newlines": ("BOOLEAN", {"default": True}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RETURN_TYPES = ("STRING",)
|
||||||
|
FUNCTION = "stringify"
|
||||||
|
CATEGORY = "KJNodes/constants"
|
||||||
|
|
||||||
|
def stringify(self, string, strip_newlines):
|
||||||
|
new_string = []
|
||||||
|
for line in io.StringIO(string):
|
||||||
|
if not line.strip().startswith("\n") and strip_newlines:
|
||||||
|
line = line.replace("\n", '')
|
||||||
|
new_string.append(line)
|
||||||
|
new_string = "\n".join(new_string)
|
||||||
|
|
||||||
|
return (new_string, )
|
||||||
|
|
||||||
|
class JoinStrings:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(cls):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"string1": ("STRING", {"default": '', "forceInput": True}),
|
||||||
|
"string2": ("STRING", {"default": '', "forceInput": True}),
|
||||||
|
"delimiter": ("STRING", {"default": ' ', "multiline": False}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RETURN_TYPES = ("STRING",)
|
||||||
|
FUNCTION = "joinstring"
|
||||||
|
CATEGORY = "KJNodes/constants"
|
||||||
|
|
||||||
|
def joinstring(self, string1, string2, delimiter):
|
||||||
|
joined_string = string1 + delimiter + string2
|
||||||
|
return (joined_string, )
|
||||||
|
|
||||||
class CreateFluidMask:
|
class CreateFluidMask:
|
||||||
|
|
||||||
RETURN_TYPES = ("IMAGE", "MASK")
|
RETURN_TYPES = ("IMAGE", "MASK")
|
||||||
@ -1467,7 +1509,7 @@ Saves an image and mask as .PNG with the mask as the alpha channel.
|
|||||||
# Loop through the existing files
|
# Loop through the existing files
|
||||||
for existing_file in os.listdir(full_output_folder):
|
for existing_file in os.listdir(full_output_folder):
|
||||||
# Check if the file matches the expected format
|
# Check if the file matches the expected format
|
||||||
match = re.fullmatch(f"{filename}_(\d+)_?\.[a-zA-Z0-9]+", existing_file)
|
match = re.fullmatch(fr"{filename}_(\d+)_?\.[a-zA-Z0-9]+", existing_file)
|
||||||
if match:
|
if match:
|
||||||
# Extract the numeric portion of the filename
|
# Extract the numeric portion of the filename
|
||||||
file_counter = int(match.group(1))
|
file_counter = int(match.group(1))
|
||||||
@ -4292,7 +4334,8 @@ Visualizes the camera poses from a .txt file with RealEstate camera intrinsics a
|
|||||||
ret_poses = [transform_matrix @ x for x in ret_poses]
|
ret_poses = [transform_matrix @ x for x in ret_poses]
|
||||||
return np.array(ret_poses, dtype=np.float32)
|
return np.array(ret_poses, dtype=np.float32)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
"INTConstant": INTConstant,
|
"INTConstant": INTConstant,
|
||||||
"FloatConstant": FloatConstant,
|
"FloatConstant": FloatConstant,
|
||||||
@ -4365,7 +4408,9 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
"Superprompt": Superprompt,
|
"Superprompt": Superprompt,
|
||||||
"RemapImageRange": RemapImageRange,
|
"RemapImageRange": RemapImageRange,
|
||||||
"CameraPoseVisualizer": CameraPoseVisualizer,
|
"CameraPoseVisualizer": CameraPoseVisualizer,
|
||||||
"BboxVisualize": BboxVisualize
|
"BboxVisualize": BboxVisualize,
|
||||||
|
"StringConstantMultiline": StringConstantMultiline,
|
||||||
|
"JoinStrings": JoinStrings,
|
||||||
}
|
}
|
||||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||||
"INTConstant": "INT Constant",
|
"INTConstant": "INT Constant",
|
||||||
@ -4440,4 +4485,6 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
|||||||
"RemapImageRange": "RemapImageRange",
|
"RemapImageRange": "RemapImageRange",
|
||||||
"CameraPoseVisualizer": "CameraPoseVisualizer",
|
"CameraPoseVisualizer": "CameraPoseVisualizer",
|
||||||
"BboxVisualize": "BboxVisualize",
|
"BboxVisualize": "BboxVisualize",
|
||||||
|
"StringConstantMultiline": "StringConstantMultiline",
|
||||||
|
"JoinStrings": "JoinStrings",
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user