Add MaskSwitch node and update documentation
- Introduced MaskSwitch node for conditional switching between two masks. - Enhanced NODE_CLASS_MAPPINGS and NODE_DISPLAY_NAME_MAPPINGS to include MaskSwitch. - Updated README files to document the new MaskSwitch and Web Image Loader features, including usage instructions and examples. - Improved error handling in MaskSwitch to return a default empty mask when no inputs are provided.
This commit is contained in:
@@ -51,6 +51,77 @@ Usage:
|
||||
4. Use color picker to set background color
|
||||
5. Adjust scaling factor and resolution limits as needed
|
||||
|
||||
### 🌐Web Image Loader
|
||||
A node for loading images from the web.
|
||||
|
||||

|
||||

|
||||
|
||||
Features:
|
||||
- Supports loading images from URLs and Base64 format
|
||||
- Automatically handles image formats
|
||||
- Supports batch image loading
|
||||
- Error handling:
|
||||
- Returns a placeholder image for invalid URLs
|
||||
- Gracefully handles exceptions, automatically removing erroneous images
|
||||
|
||||
Usage:
|
||||
1. Add the node to your workflow
|
||||
2. Input the image URL
|
||||
3. The node will automatically load and process the image
|
||||
4. The output image can be connected to other nodes requiring image input
|
||||
|
||||
Use Cases:
|
||||
- Loading images from online resources
|
||||
- Dynamic image processing workflows
|
||||
- Batch image downloading and processing
|
||||
|
||||
### 🖼️Image to Base64 Encoder
|
||||
A node for converting images to Base64 encoding.
|
||||
|
||||

|
||||
|
||||
Features:
|
||||
- Supports various image formats (JPEG, PNG, BMP, etc.)
|
||||
- Automatically handles image size and format
|
||||
- Supports batch image encoding
|
||||
- Error handling:
|
||||
- Returns error information for invalid images
|
||||
- Gracefully handles exceptions, ensuring workflow continuity
|
||||
|
||||
Usage:
|
||||
1. Add the node to your workflow
|
||||
2. Input the image file or image path
|
||||
3. The node will automatically convert the image to Base64 encoding
|
||||
4. The output Base64 string can be connected to other nodes requiring Base64 input
|
||||
|
||||
Use Cases:
|
||||
- Image data transmission
|
||||
- Embedding images in HTML or JSON
|
||||
- Dynamic image processing workflows
|
||||
- Batch image encoding and processing
|
||||
|
||||
### 🔀 Switch Node (Image Switch, Text Switch)
|
||||
Switch nodes are used to dynamically switch between different input or output paths in a workflow.
|
||||
|
||||

|
||||
|
||||
Features:
|
||||
- Supports multiple input and output types
|
||||
- Configurable switching conditions
|
||||
- Automatically handles input and output connections
|
||||
|
||||
Usage:
|
||||
1. Add the Switch node to your workflow
|
||||
2. Configure switching conditions (e.g., boolean values, numerical ranges, etc.)
|
||||
3. Connect different input and output paths
|
||||
4. Automatically switch paths based on conditions
|
||||
|
||||
Use Cases:
|
||||
- Dynamically adjusting workflows
|
||||
- Conditional branch processing
|
||||
- Multi-path selection
|
||||
|
||||
### ✂️Remove Empty Lines And Leading Spaces
|
||||
A text processing node that cleans up text by removing empty lines and leading/trailing spaces.
|
||||

|
||||
@@ -244,6 +315,33 @@ Usage:
|
||||
MIT License
|
||||
|
||||
## 🤝 Updates
|
||||
### v0.2.2 (2024-01-09)
|
||||
- Added Mask Switch node
|
||||
- Support switching between two masks based on conditions
|
||||
- Provides default blank mask handling
|
||||
- Optimized exception handling mechanism
|
||||
- Maintains mask format and quality
|
||||
|
||||
### v0.2.1 (2024-01-07)
|
||||
- Added Web Image Loader node
|
||||
- Support loading images from URLs and Base64
|
||||
- Automatic image format handling
|
||||
- Support batch image loading
|
||||
- Error handling: returns placeholder image for invalid URLs, graceful exception handling
|
||||
- Cache support for improved loading efficiency
|
||||
- Preview feature: generates and saves preview images
|
||||
|
||||
### v0.2.0 (2024-01-06)
|
||||
- Added Image Switch node
|
||||
- Support switching between two images based on conditions
|
||||
- Provides default blank image handling
|
||||
- Optimized exception handling mechanism
|
||||
- Maintains image format and quality
|
||||
|
||||
- Added Text Switch node
|
||||
- Support switching between two texts based on conditions
|
||||
- Provides default blank text handling
|
||||
- Optimized exception handling mechanism
|
||||
|
||||
### v0.1.9 (2024-01-05)
|
||||
- Enhanced Image Resolution Adjuster
|
||||
|
||||
+102
@@ -62,8 +62,81 @@
|
||||
8. 描边颜色会自动根据 `background_color` 设置的背景色计算反色
|
||||
9. 输出图像尺寸会自动调整(宽高各增加 2 像素)
|
||||
|
||||
### 🌐Web图像加载器 (Web Image Loader)
|
||||
一个用于从网络加载图像的节点。
|
||||
|
||||

|
||||

|
||||
|
||||
特点:
|
||||
- 支持从URL加载图像,支持Base64格式
|
||||
- 自动处理图像格式
|
||||
- 支持批量图像加载
|
||||
- 错误处理:
|
||||
- 无效URL时返回占位图像
|
||||
- 优雅处理异常,自动剔除错误图像
|
||||
|
||||
使用方法:
|
||||
1. 将节点添加到工作流
|
||||
2. 输入图像URL
|
||||
3. 节点将自动加载并处理图像
|
||||
4. 输出图像可连接到需要图像输入的其他节点
|
||||
|
||||
使用场景:
|
||||
- 从网络资源加载图像
|
||||
- 动态图像处理工作流
|
||||
- 批量图像下载和处理
|
||||
|
||||
### 🖼️图像转Base64编码器 (Image to Base64 Encoder)
|
||||
一个用于将图像转换为Base64编码的节点。
|
||||
|
||||

|
||||
|
||||
特点:
|
||||
- 支持多种图像格式(JPEG, PNG, BMP等)
|
||||
- 自动处理图像大小和格式
|
||||
- 支持批量图像编码
|
||||
- 错误处理:
|
||||
- 无效图像时返回错误信息
|
||||
- 优雅处理异常,确保工作流不中断
|
||||
|
||||
使用方法:
|
||||
1. 将节点添加到工作流
|
||||
2. 输入图像文件或图像路径
|
||||
3. 节点将自动将图像转换为Base64编码
|
||||
4. 输出Base64编码字符串可连接到需要Base64输入的其他节点
|
||||
|
||||
使用场景:
|
||||
- 图像数据传输
|
||||
- 图像嵌入HTML或JSON
|
||||
- 动态图像处理工作流
|
||||
- 批量图像编码和处理
|
||||
|
||||
### 🔀 Switch节点(Image Switch,Text Switch)
|
||||
Switch节点用于在工作流中动态切换不同的输入或输出路径。
|
||||
|
||||

|
||||
|
||||
特点:
|
||||
- 支持多种输入和输出类型
|
||||
- 可配置的切换条件
|
||||
- 自动处理输入输出连接
|
||||
|
||||
使用方法:
|
||||
1. 将Switch节点添加到工作流
|
||||
2. 配置切换条件(如布尔值、数值范围等)
|
||||
3. 连接不同的输入和输出路径
|
||||
4. 根据条件自动切换路径
|
||||
|
||||
使用场景:
|
||||
- 动态调整工作流
|
||||
- 条件分支处理
|
||||
- 多路径选择
|
||||
|
||||
|
||||
### ✂️空行和前导空格清理器 (Remove Empty Lines And Leading Spaces)
|
||||
一个用于清理文本中的空行和前导/尾随空格的文本处理节点。
|
||||
|
||||

|
||||
|
||||
特点:
|
||||
@@ -261,6 +334,35 @@ MIT License
|
||||
|
||||
## 🤝 更新说明
|
||||
|
||||
### v0.2.2 (2024-01-09)
|
||||
- 新增 Mask Switch 节点
|
||||
- 支持根据条件在两个蒙版之间切换
|
||||
- 提供默认空白蒙版处理
|
||||
- 优化异常处理机制
|
||||
- 保持蒙版格式和质量
|
||||
|
||||
### v0.2.1 (2024-01-07)
|
||||
- 新增 Web图像加载器 节点
|
||||
- 支持从 URL 和 Base64 加载图像
|
||||
- 自动处理图像格式
|
||||
- 支持批量图像加载
|
||||
- 错误处理:无效 URL 时返回占位图像,优雅处理异常
|
||||
- 支持缓存功能,提升加载效率
|
||||
- 预览功能:生成预览图像并保存
|
||||
|
||||
### v0.2.0 (2024-01-06)
|
||||
- 新增图像切换器节点
|
||||
- 支持根据条件在两个图像之间切换
|
||||
- 提供默认空白图像处理
|
||||
- 优化异常处理机制
|
||||
- 保持图像格式和质量
|
||||
|
||||
- 新增文本切换器节点
|
||||
- 支持根据条件在两个文本之间切换
|
||||
- 提供默认空白文本处理
|
||||
- 优化异常处理机制
|
||||
- 保持文本格式和内容
|
||||
|
||||
### v0.1.9 (2024-01-05)
|
||||
- 优化图像分辨率调整器
|
||||
- 新增蒙版羽化(feather)功能
|
||||
|
||||
@@ -23,6 +23,7 @@ from .modules.text.multiline_text_input import MultilineTextInput
|
||||
from .modules.text.remove_empty_lines import RemoveEmptyLinesAndLeadingSpaces
|
||||
from .modules.switch.switch_node import TextSwitch
|
||||
from .modules.switch.switch_node import ImageSwitch
|
||||
from .modules.switch.switch_node import MaskSwitch
|
||||
from .modules.web.web_image_loader import WebImageLoader
|
||||
from .modules.images.image_base64_converter import ImageToBase64
|
||||
|
||||
@@ -30,6 +31,7 @@ from .modules.images.image_base64_converter import ImageToBase64
|
||||
|
||||
|
||||
|
||||
|
||||
# 节点类映射
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"MaskPreview": MaskPreview,
|
||||
@@ -46,6 +48,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"RemoveEmptyLinesAndLeadingSpaces": RemoveEmptyLinesAndLeadingSpaces,
|
||||
"TextSwitch": TextSwitch,
|
||||
"ImageSwitch": ImageSwitch,
|
||||
"MaskSwitch": MaskSwitch,
|
||||
"WebImageLoader": WebImageLoader,
|
||||
}
|
||||
|
||||
@@ -65,6 +68,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"RemoveEmptyLinesAndLeadingSpaces": "Remove Empty Lines And Leading Spaces 📝",
|
||||
"TextSwitch": "Text Switch 🔄",
|
||||
"ImageSwitch": "Image Switch 🔄",
|
||||
"MaskSwitch": "Mask Switch 🔄",
|
||||
"WebImageLoader": "Web Image Loader 🌐(URL Or Base64)",
|
||||
}
|
||||
|
||||
|
||||
@@ -79,13 +79,56 @@ class TextSwitch:
|
||||
print(f"Error in TextSwitch: {str(e)}")
|
||||
return ("",)
|
||||
|
||||
class MaskSwitch:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"use_first": ("BOOLEAN", {"default": True}),
|
||||
},
|
||||
"optional": {
|
||||
"mask_1": ("MASK",),
|
||||
"mask_2": ("MASK",),
|
||||
},
|
||||
"_meta": {
|
||||
"preferred_width": 300,
|
||||
"maintain_dimensions": True
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("MASK",)
|
||||
RETURN_NAMES = ("mask",)
|
||||
FUNCTION = "switch_mask"
|
||||
CATEGORY = "🎨Painting👓Coder/🔄Switch"
|
||||
|
||||
def switch_mask(self, use_first, mask_1=None, mask_2=None):
|
||||
try:
|
||||
# 创建空白掩码作为默认值
|
||||
empty_mask = torch.zeros((1, 1024, 1024))
|
||||
|
||||
# 如果两个输入都为空,返回空白掩码
|
||||
if mask_1 is None and mask_2 is None:
|
||||
return (empty_mask,)
|
||||
|
||||
# 根据use_first选择输出
|
||||
if use_first:
|
||||
return (mask_1,) if mask_1 is not None else (empty_mask,)
|
||||
else:
|
||||
return (mask_2,) if mask_2 is not None else (empty_mask,)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error in MaskSwitch: {str(e)}")
|
||||
return (torch.zeros((1, 512, 512)),)
|
||||
|
||||
# 添加到 ComfyUI 节点注册
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"ImageSwitch": ImageSwitch,
|
||||
"TextSwitch": TextSwitch
|
||||
"TextSwitch": TextSwitch,
|
||||
"MaskSwitch": MaskSwitch
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"ImageSwitch": "Image Switch 🔄",
|
||||
"TextSwitch": "Text Switch 🔄"
|
||||
"TextSwitch": "Text Switch 🔄",
|
||||
"MaskSwitch": "Mask Switch 🔄"
|
||||
}
|
||||
Reference in New Issue
Block a user