title: Python Pillow: Make gradient for transparency
body: <p>I have code which add gradient on image.</p>
  
  <pre><code>def st(path, gradient_magnitude=2.):
      im = Image.open(path)
      if im.mode != 'RGBA':
          im = im.convert('RGBA')
      width, height = im.size
      gradient = Image.new('L', (width, 1), color=0xFF)
      for x in range(width):
          gradient.putpixel((x, 0), int(255 * (1 - gradient_magnitude * float(x) / width)))
      alpha = gradient.resize(im.size)
      black_im = Image.new('RGBA', (width, height), color=0x000000)
      black_im.putalpha(alpha)
      gradient_im = Image.alpha_composite(im, black_im)
      gradient_im.save('out.jpg', 'JPEG')
  </code></pre>
  
  <p>After run I get this image <a href="https://i.stack.imgur.com/oDUcD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oDUcD.jpg" alt="enter image description here"></a></p>
  
  <p>How can I make gradient more transparency?</p>