from PIL import Image def alpha_composite(img: Image, background: Image = None): if not background: background = Image.new("RGBA", img.size, (255, 255, 255)) result = Image.alpha_composite(background, img) result = result.convert("RGB") return result