from PIL import Image
import os
def apply_alpha_to_texture(texture_path, alpha_path, output_path):
texture = Image.open(texture_path).convert("RGBA")
alpha = Image.open(alpha_path).convert("L")
width, height = texture.size
for x in range(width):
for y in range(height):
alpha_value = alpha.getpixel((x, y))
texture.putpixel((x, y), texture.getpixel((x, y))[:-1] + (alpha_value,))
texture.save(output_path, "PNG")
basePath = "F:/aaa/bbb"
outBasePath = "F:/aaa/bbb/output"
texture_path = os.path.join(basePath, 'basecolor.png')
alpha_path = os.path.join(basePath, 'alpha.png')
output_path = os.path.join(outBasePath, 'result.png')
apply_alpha_to_texture(texture_path, alpha_path, output_path)