PIL transparency gradient

Allard Warrink allardwarrink at gmail.com
Sat Mar 1 18:17:46 EST 2008


Thanks for the inspiration!
This what I did (Using your Python Editor (SPE), I really like to work
with SPE, keep up the good work!!):

#############################################
import Image, os
p = # path to image file

im = Image.open(p)
# check if im has Alpha band...
if im.mode != 'RGBA':
    im = im.convert('RGBA')
# create a vertical gradient...
gradient = Image.new('L', (1,255))
for y in range(255):
    gradient.putpixel((0,254-y),y)
# resize the gradient to the size of im...
alpha = gradient.resize(im.size)
# put alpha in the alpha band of im...
im.putalpha(alpha)
# Save as png...
im.save(os.path.splitext(p)[0] + '.png', 'PNG

#############################################



More information about the Python-list mailing list