channel rgba

This commit is contained in:
bilt 2025-07-25 18:09:10 +08:00
parent 8ad8a4c9a5
commit bb9d1b626d

View File

@ -493,7 +493,7 @@ class PromptServer():
)
# 处理静态图像文件
if channel == 'rgb' or channel == 'rgba':
if channel == 'rgb':
with Image.open(file) as img:
if img.mode == "RGBA":
r, g, b, a = img.split()
@ -524,6 +524,32 @@ class PromptServer():
return web.Response(body=alpha_buffer.read(), content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""})
elif channel == 'rgba':
with Image.open(file) as img:
# 确保图像是 RGBA 模式
if img.mode != 'RGBA':
if img.mode == 'RGB':
# RGB -> RGBAAlpha=255
new_img = img.convert('RGBA')
else:
# 其他模式(如 L/LA/P-> RGBA
new_img = Image.new('RGBA', img.size, (0, 0, 0, 255))
new_img.paste(img, (0, 0), img) # 保留原图的 Alpha如果有
else:
new_img = img # 已经是 RGBA无需转换
# 保存为 PNG 并返回
buffer = BytesIO()
new_img.save(buffer, format='PNG')
buffer.seek(0)
return web.Response(
body=buffer.read(),
content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""}
)
else:
# Get content type from mimetype, defaulting to 'application/octet-stream'
content_type = mimetypes.guess_type(filename)[0] or 'application/octet-stream'