title: How can i use a black and white image to mask an image to another image in python using Pillow?
body: <p>I am trying to use a black and white image to mask out certain areas of image1 and paste it onto image2 in python using Pillow. I've tried using "PIL.Image.composite(image1, image2, mask)" but it didnt work or i did something wrong.
  Sorry that i dont have the code to that anymore,
  the only code i have left is </p>
  
  <pre><code>from PIL import Image, ImageEnhance, ImageOps, ImageDraw, ImageFilter
  import os
  avatars = []
  
  for img in os.listdir():
    if img.endswith(".png") is True:
      avatars.append(img)
  
  #open the images
  mask = image.open("./masks/roundmask.png")
  avatar1 = Image.open(avatars[0]).resize((128,128))
  avatar2 = Image.open(avatars[1]).resize((128,128))
  
  """
  mask the image avatar1 using the mask image and paste it on top of avatar2
  """
  end = Image.open("./template/image.png").paste(avatar1, (190,93)).paste(avatar2, (420,38))
  
  end.save("./finished/end.png")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/u35XI.png" rel="nofollow noreferrer">avatar1</a></p>
  
  <p><a href="https://i.stack.imgur.com/cUOw5.png" rel="nofollow noreferrer">avatar2</a> </p>
  
  <p><a href="https://i.stack.imgur.com/YF0qK.png" rel="nofollow noreferrer">mask</a></p>
  
  <p><a href="https://i.stack.imgur.com/iAbaZ.png" rel="nofollow noreferrer">expected result</a></p>