Skip to content

Commit

Permalink
commit TextJoinV2 node
Browse files Browse the repository at this point in the history
  • Loading branch information
chflame163 committed Sep 29, 2024
1 parent 42b3af6 commit 92f6366
Show file tree
Hide file tree
Showing 7 changed files with 510 additions and 152 deletions.
578 changes: 433 additions & 145 deletions README.MD

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions README_CN.MD
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
## 更新说明
<font size="4">**如果本插件更新后出现依赖包错误,请双击运行插件目录下的```install_requirements.bat```(官方便携包),或 ```install_requirements_aki.bat```(秋叶整合包) 重新安装依赖包。

* 添加 [TextJoinV2](#TextJoinV2) 节点,在TextJion基础上增加分隔符选项。
* 添加 [GaussianBlurV2](#GaussianBlurV2) 节点,参数精度提升到0.01。
* 添加 [UserPromptGeneratorTxtImgWithReference](#UserPromptGeneratorTxtImgWithReference) 节点。
* 添加 [GrayValue](#GrayValue) 节点,输出RGB色值对应的灰度值。
Expand Down Expand Up @@ -1406,6 +1407,9 @@ box_preview: 裁切位置预览。
![image](image/text_join_example.jpg)
将多段文字组合为一段。

### <a id="table1">TextJoinV2</a>
![image](image/text_join_v2_node.jpg)
[TextJoin](#TextJoin) 的基础上增加了分隔符选项。

### <a id="table1">PrintInfo</a>
![image](image/print_info_node.jpg)
Expand Down
Binary file added image/text_join_v2_node.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion py/image_scale_by_aspect_ratio_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def image_scale_by_aspect_ratio(self, aspect_ratio, proportional_width, proporti
mask = torch.unsqueeze(mask, 0)
for m in mask:
m = torch.unsqueeze(m, 0)
print(f"m.shape={m.shape}")
if not is_valid_mask(m) and m.shape==torch.Size([1,64,64]):
log(f"Warning: {NODE_NAME} input mask is empty, ignore it.", message_type='warning')
else:
Expand Down
34 changes: 31 additions & 3 deletions py/imagefunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,7 @@ def file_is_extension(filename:str, ext_list:tuple) -> bool:
return False

# 遍历目录下包括子目录指定后缀文件,返回字典
def collect_files(default_dir:str, root_dir:str, suffixes:tuple):
def collect_files(root_dir:str, suffixes:tuple, default_dir:str=""):
result = {}
for dirpath, _, filenames in os.walk(root_dir):
for file in filenames:
Expand Down Expand Up @@ -2285,12 +2285,12 @@ def get_resource_dir() -> list:

LUT_DICT = {}
for dir in default_lut_dir:
LUT_DICT.update(collect_files(default_lut_dir[0], dir, ('.cube'))) # 后缀要小写
LUT_DICT.update(collect_files(root_dir=dir, suffixes= ('.cube'), default_dir=default_lut_dir[0] )) # 后缀要小写
LUT_LIST = list(LUT_DICT.keys())

FONT_DICT = {}
for dir in default_font_dir:
FONT_DICT.update(collect_files(default_font_dir[0], dir, ('.ttf', '.otf'))) # 后缀要小写
FONT_DICT.update(collect_files(root_dir=dir, suffixes=('.ttf', '.otf'), default_dir=default_font_dir[0])) # 后缀要小写
FONT_LIST = list(FONT_DICT.keys())

return (LUT_DICT, FONT_DICT)
Expand Down Expand Up @@ -2362,6 +2362,34 @@ def draw_bounding_boxes(image: Image, bboxes: list, color: str = "#FF0000", line

return image

def draw_bbox(image: Image, bbox: tuple, color: str = "#FF0000", line_width: int = 5, title: str = "", font_size: int = 10) -> Image:
"""
Draw bounding boxes on the image using the coordinates provided in the bboxes dictionary.
"""

(_, FONT_DICT) = get_resource_dir()

font = ImageFont.truetype(list(FONT_DICT.items())[0][1], font_size)

draw = ImageDraw.Draw(image)
width, height = image.size
if line_width < 0: # auto line width
line_width = (image.width + image.height) // 1000

random_color = generate_random_color()
if color != "random":
random_color = color
xmin = min(bbox[0], bbox[2])
xmax = max(bbox[0], bbox[2])
ymin = min(bbox[1], bbox[3])
ymax = max(bbox[1], bbox[3])
draw.rectangle([xmin, ymin, xmax, ymax], outline=random_color, width=line_width)
if title != "":
draw.text((xmin, ymin - font_size*1.2), title, font=font, fill=random_color)

return image



'''Constant'''

Expand Down
43 changes: 41 additions & 2 deletions py/text_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,49 @@ def text_join(self, **kwargs):
return (combined_text.encode('unicode-escape').decode('unicode-escape'),)


class LS_TextJoinV2:

def __init__(self):
pass

@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text_1": ("STRING", {"multiline": False,"forceInput":True}),
"delimiter": ("STRING", {"default": ",", "multiline": False}),
},
"optional": {
"text_2": ("STRING", {"multiline": False,"forceInput":True}),
"text_3": ("STRING", {"multiline": False,"forceInput":True}),
"text_4": ("STRING", {"multiline": False,"forceInput":True}),
}
}

RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "text_join"
CATEGORY = '😺dzNodes/LayerUtility/Data'

def text_join(self, text_1, delimiter, text_2=None, text_3=None, text_4=None):

texts = [text_1]
if text_2 is not None:
texts.append(text_2)
if text_3 is not None:
texts.append(text_3)
if text_4 is not None:
texts.append(text_4)
combined_text = delimiter.join(texts)

return (combined_text.encode('unicode-escape').decode('unicode-escape'),)

NODE_CLASS_MAPPINGS = {
"LayerUtility: TextJoin": TextJoin
"LayerUtility: TextJoin": TextJoin,
"LayerUtility: TextJoinV2": LS_TextJoinV2
}

NODE_DISPLAY_NAME_MAPPINGS = {
"LayerUtility: TextJoin": "LayerUtility: TextJoin"
"LayerUtility: TextJoin": "LayerUtility: TextJoin",
"LayerUtility: TextJoinV2": "LayerUtility: TextJoinV2"
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui_layerstyle"
description = "A set of nodes for ComfyUI it generate image like Adobe Photoshop's Layer Style. the Drop Shadow is first completed node, and follow-up work is in progress."
version = "1.0.68"
version = "1.0.70"
license = "MIT"
dependencies = ["numpy", "pillow", "torch", "matplotlib", "Scipy", "scikit_image", "scikit_learn", "opencv-contrib-python", "pymatting", "segment_anything", "timm", "addict", "yapf", "colour-science", "wget", "mediapipe", "loguru", "typer_config", "fastapi", "rich", "google-generativeai", "diffusers", "omegaconf", "tqdm", "transformers", "kornia", "image-reward", "ultralytics", "blend_modes", "blind-watermark", "qrcode", "pyzbar", "transparent-background", "huggingface_hub", "accelerate", "bitsandbytes", "torchscale", "wandb", "hydra-core", "psd-tools", "inference-cli[yolo-world]", "inference-gpu[yolo-world]", "onnxruntime"]

Expand Down

0 comments on commit 92f6366

Please sign in to comment.