code: def _remove_white_background(image):
      
      from PIL import ImageMath, Image
      if image.mode == "RGBA":
          bands = image.split()
          a = bands[3]
          rgb = [
              ImageMath.eval(
                  'convert('
                  'float(x + a - 255) * 255.0 / float(max(a, 1)) * '
                  'float(min(a, 1)) + float(x) * float(1 - min(a, 1))'
                  ', "L")',
                  x=x, a=a
              )
              for x in bands[:3]
          ]
          return Image.merge(bands=rgb + [a], mode="RGBA")
  
      return image
docs: Remove white background in the preview image.