mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-08-16 03:23:32 +08:00
channel rgba
This commit is contained in:
parent
8ad8a4c9a5
commit
bb9d1b626d
28
server.py
28
server.py
@ -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 -> RGBA(Alpha=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'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user