File size: 229 Bytes
613c9ab
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
from PIL import Image


def flatten(img, bgcolor):
    # Replace transparency with bgcolor
    if img.mode in ("RGB"):
        return img
    return Image.alpha_composite(Image.new("RGBA", img.size, bgcolor), img).convert("RGB")