我正在尝试使用黑白图像来掩盖 image1 的某些区域,并使用 Pillow 将其粘贴到 python 中的 image2 上。我尝试过使用“PIL.Image.composite(image1, image2, mask)”,但它不起作用或者我做错了什么。抱歉,我不再有该代码,我剩下的唯一代码是
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")
Run Code Online (Sandbox Code Playgroud)