Vertically fade an image with transparent background to transparency from the top (Pillow)

Viewed 17

I am looking for a way to fade images that already have a transparent images from the top. This piece of code from here does what I'm looking for, but I can't seem to reverse the side to fade the image from the top instead of the bottom.

from PIL import Image

im = Image.open('bird.jpg')
width, height = im.size
pixels = im.load()
for y in range(int(height*.55), int(height*.75)):
    for x in range(width):
        alpha = pixels[x, y][3]-int((y - height*.55)/height/.20 * 255)
        if alpha <= 0:
            alpha = 0
        pixels[x, y] = pixels[x, y][:3] + (alpha,)
for y in range(y, height):
    for x in range(width):
        pixels[x, y] = pixels[x, y][:3] + (0,)
bg.save('birdfade.png')
0 Answers
Related