增加 filename_prefix 参数
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
- 支持URL和Base64图像响应格式
|
||||
- 完整的错误处理机制
|
||||
- 同时输出图像和图片URL链接
|
||||
- 自动保存图片到本地文件,支持自定义文件名前缀
|
||||
|
||||
## 安装
|
||||
|
||||
@@ -46,6 +47,7 @@ pip install -r requirements.txt
|
||||
- **guidance_scale**: 文本描述的影响程度(默认:2.5,范围:1.0-10.0)
|
||||
- **aspect_ratio**: 图像宽高比,支持1.5K分辨率预设(默认:1:1)
|
||||
- **return_url**: 是否返回图片URL链接(默认:True)
|
||||
- **filename_prefix**: 本地保存文件名前缀(默认:seedream)
|
||||
|
||||
### 支持的图像分辨率 (1.5K)
|
||||
|
||||
@@ -83,6 +85,7 @@ pip install -r requirements.txt
|
||||
| guidance_scale | scale | 引导强度 |
|
||||
| aspect_ratio | width/height | 自动设置宽高比 |
|
||||
| return_url | return_url | 返回图片URL |
|
||||
| filename_prefix | - | 本地文件名前缀 |
|
||||
|
||||
## 节点位置
|
||||
|
||||
@@ -112,6 +115,8 @@ pip install -r requirements.txt
|
||||
- 请合理使用API避免超出配额限制
|
||||
- 网络环境需要能够访问火山引擎API服务
|
||||
- image_url输出可以用于后续的图像处理或保存链接
|
||||
- 生成的图片会自动保存到`output`目录下,文件名格式为`{filename_prefix}_0001.png`
|
||||
- 如果文件名重复,序号会自动递增(如:`seedream_0002.png`)
|
||||
|
||||
## 技术支持
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ class VolcengineSeeDreamV3Node:
|
||||
"guidance_scale": ("FLOAT", {"default": 2.5, "min": 1.0, "max": 10.0, "step": 0.1}),
|
||||
"aspect_ratio": (["1:1", "4:3", "3:2", "16:9", "9:16", "21:9"], {"default": "1:1"}),
|
||||
"return_url": ("BOOLEAN", {"default": True}),
|
||||
"filename_prefix": ("STRING", {"default": "seedream", "multiline": False}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,8 +181,42 @@ class VolcengineSeeDreamV3Node:
|
||||
}
|
||||
return resolution_map.get(aspect_ratio, (1536, 1536))
|
||||
|
||||
def get_unique_filename(self, prefix, output_dir="output", extension="png"):
|
||||
"""Generate unique filename with auto-incrementing number"""
|
||||
if not os.path.exists(output_dir):
|
||||
os.makedirs(output_dir)
|
||||
|
||||
counter = 1
|
||||
while True:
|
||||
filename = f"{prefix}_{counter:04d}.{extension}"
|
||||
filepath = os.path.join(output_dir, filename)
|
||||
if not os.path.exists(filepath):
|
||||
return filepath, filename
|
||||
counter += 1
|
||||
|
||||
def save_image_from_tensor(self, image_tensor, filename_prefix):
|
||||
"""Save image tensor to local file and return filepath"""
|
||||
try:
|
||||
# Convert tensor back to PIL Image
|
||||
image_array = image_tensor.squeeze(0).cpu().numpy()
|
||||
image_array = (image_array * 255).astype(np.uint8)
|
||||
image = Image.fromarray(image_array)
|
||||
|
||||
# Get unique filename
|
||||
filepath, filename = self.get_unique_filename(filename_prefix)
|
||||
|
||||
# Save image
|
||||
image.save(filepath)
|
||||
print(f"Image saved to: {filepath}")
|
||||
|
||||
return filepath
|
||||
|
||||
except Exception as e:
|
||||
print(f"Failed to save image: {str(e)}")
|
||||
return ""
|
||||
|
||||
def generate_image(self, access_key, secret_key, prompt, use_pre_llm=False,
|
||||
seed=-1, guidance_scale=2.5, aspect_ratio="1:1", return_url=True):
|
||||
seed=-1, guidance_scale=2.5, aspect_ratio="1:1", return_url=True, filename_prefix="seedream"):
|
||||
"""
|
||||
Generate image using Volcengine SeeDream V3 API
|
||||
"""
|
||||
@@ -265,7 +300,11 @@ class VolcengineSeeDreamV3Node:
|
||||
else:
|
||||
raise Exception("No valid image data found in API response")
|
||||
|
||||
# Save image to local file
|
||||
saved_filepath = self.save_image_from_tensor(image_tensor, filename_prefix)
|
||||
|
||||
print("Image generated successfully!")
|
||||
print(f"Image saved as: {saved_filepath}")
|
||||
return (image_tensor, image_url)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user