from PIL import Image, ImageColor def white_background(im, requested_size, opts): try: background = Image.new('RGB', im.size, ImageColor.getcolor('white', 'RGB')) background.paste(im, mask=im.split()[3]) return background except: return im