Just to share an enhanced version and add some visuals (because visuals are good)...
# 'divisor' : How much we expand the gradient (less is more)
# 'switch' : If True, start gradient from bottom to top
def fadeDownFromBlack(pic, divisor, switch=False):  
   w = getWidth(pic)
   h = getHeight(pic)
   startY = 0
   endY = min(h-1, int(h/float(divisor)))
   inc = 1
   if (switch):
     startY = h-1
     endY = max(0, h-1 - int(h/float(divisor)))
     inc = -1
   color_ratio = float(divisor)/h
   for y in range(startY, endY, inc): 
       for x in range(0,w):
           px = getPixel(pic, x, y )
           setRed(px, abs(startY - y)*(color_ratio)*getRed(px))
           setGreen(px, abs(startY - y)*(color_ratio)*getGreen(px))
           setBlue(px, abs(startY - y)*(color_ratio)*getBlue(px))
file = pickAFile()
picture = makePicture(file)
# The following commented line answers the question
#fadeDownFromBlack(picture, 2)
fadeDownFromBlack(picture, 0.7, True)
writePictureTo(picture, "/home/mad-king.png")
show(picture)
Output (Painting by Corneliu Baba - The Mad King):
............
......................
............