from PIL import Image
import os
def pic_connect(base_layer_path, folders_path, save_path):
base_layer = Image.open(base_layer_path)
base_layer = base_layer.convert('RGBA')
folders = os.listdir(folders_path)
for folder in folders:
folder_path = os.path.join(folders_path, folder)
layer = Image.open(folder_path)
layer = layer.convert('RGBA')
heigh, width = layer.size
for i in range(heigh):
for j in range(width):
r, g, b, a = layer.getpixel((i, j))
if r == 0:
layer.putpixel((i, j), (0, 0, 0, 0))
else:
layer.putpixel((i, j), (128, 0, 0, 255))
base_layer.paste(layer, (0, 0), layer)
base_layer.save(save_path + "/" + "connect.png")
if __name__ == "__main__":
base_layer_path = r''
folders_path = r''
save_path = r''
pic_connect(base_layer_path,folders_path,save_path)