def max_alpha(a, b):
    im_a = a.load()
im_b = b.load()
width, height = a.size
alpha = Image.new('L', (width, height))
im = alpha.load()
for x in range(width):
    for y in range(height):
        im[x, y] = max(im_a[x, y], im_b[x, y])
return alpha
PIL merge of two images with alpha channels - not working as expected