iasjkk commited on
Commit
fa8f4e5
·
verified ·
1 Parent(s): bda8de6

Create RGBA2RGB_conversion.py

Browse files
Files changed (1) hide show
  1. RGBA2RGB_conversion.py +12 -0
RGBA2RGB_conversion.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+
3
+ def convert_png_with_alpha_to_png(png_path, output_png_path, background_color=(255, 255, 255)):
4
+ png = Image.open(png_path)
5
+ mode = png.mode
6
+ png.load()
7
+ background = Image.new("RGB", png.size, background_color)
8
+ if 'A' in mode:
9
+ background.paste(png, mask=png.split()[3])
10
+ else:
11
+ background.paste(png)
12
+ background.save(output_png_path, 'PNG')