add an option for img2img background color

This commit is contained in:
AUTOMATIC
2022-12-24 09:46:35 +03:00
parent 1d9eaf94e3
commit 9441c28c94
4 changed files with 14 additions and 2 deletions

View File

@@ -622,3 +622,14 @@ def image_data(data):
pass
return '', None
def flatten(img, bgcolor):
"""replaces transparency with bgcolor (example: "#ffffff"), returning an RGB mode image with no transparency"""
if img.mode == "RGBA":
background = Image.new('RGBA', img.size, bgcolor)
background.paste(img, mask=img)
img = background
return img.convert('RGB')