Skip to content

Instantly share code, notes, and snippets.

@CathyLou
Created July 25, 2021 05:18
Show Gist options
  • Select an option

  • Save CathyLou/8ebd5deab807fc217389bec31d71c4a5 to your computer and use it in GitHub Desktop.

Select an option

Save CathyLou/8ebd5deab807fc217389bec31d71c4a5 to your computer and use it in GitHub Desktop.
import os
from PIL import Image
import numpy as np
def add_alpha_channel_path(source_img_path,alpha_img_path):
alpha_img=Image.open(alpha_img_path)
source_img=Image.open(source_img_path)
output_img = source_img.convert('RGBA')
output_img.putalpha(alpha_img)
result_img=Image.new('RGB',output_img.size,(255,255,255))
result_img.paste(output_img,(0,0),output_img)
return result_img
def add_alpha_channel(source_img,alpha_img):
output_img = source_img.convert('RGBA')
output_img.putalpha(alpha_img)
result_img=Image.new('RGB',output_img.size,(255,255,255))
result_img.paste(output_img,(0,0),output_img)
return result_img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment