def copy_image_on_background ( image , color = WHITE ) : background = Image . new ( "RGB" , image . size , color ) background . paste ( image , mask = image . split ( ) [ 3 ] ) return background
how to set an image as background in python
Create a new image by copying the image on a * color * background .
def copy_image_on_background(image, color=WHITE):
    """
    Create a new image by copying the image on a *color* background.

    Args:
        image (PIL.Image.Image): Image to copy
        color (tuple): Background color usually WHITE or BLACK

    Returns:
        PIL.Image.Image

    """
    background = Image.new("RGB", image.size, color)
    background.paste(image, mask=image.split()[3])
    return background