diff options
author | AUTOMATIC <16777216c@gmail.com> | 2022-12-24 06:46:35 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2022-12-24 06:46:35 +0000 |
commit | 9441c28c947588d756e279a8cd5db6c0b4a8d2e4 (patch) | |
tree | 414c854735b316e0c05ad58dd5a9f02f1cd02fd9 /modules/images.py | |
parent | 1d9eaf94e32e2d6b817a6796ffa7b0a814580015 (diff) | |
download | stable-diffusion-webui-gfx803-9441c28c947588d756e279a8cd5db6c0b4a8d2e4.tar.gz stable-diffusion-webui-gfx803-9441c28c947588d756e279a8cd5db6c0b4a8d2e4.tar.bz2 stable-diffusion-webui-gfx803-9441c28c947588d756e279a8cd5db6c0b4a8d2e4.zip |
add an option for img2img background color
Diffstat (limited to 'modules/images.py')
-rw-r--r-- | modules/images.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/images.py b/modules/images.py index ad97980c..8bcbc8d9 100644 --- a/modules/images.py +++ b/modules/images.py @@ -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')
|