In [1]:
from PIL import Image, ImageDraw, ImageFilter

In [2]:
im_rgb = Image.open('data/src/lena.jpg')

In [3]:
im_rgba = im_rgb.copy()
im_rgba.putalpha(128)
im_rgba.save('data/dst/pillow_putalpha_solid.png')


In [4]:
im_a = Image.new("L", im_rgb.size, 0)
draw = ImageDraw.Draw(im_a)
draw.ellipse((140, 50, 260, 170), fill=255)


In [5]:
im_rgba = im_rgb.copy()
im_rgba.putalpha(im_a)
im_rgba_crop = im_rgba.crop((140, 50, 260, 170))
im_rgba_crop.save('data/dst/pillow_putalpha_circle.png')


In [6]:
im_a_blur = im_a.filter(ImageFilter.GaussianBlur(4))


In [7]:
im_rgba = im_rgb.copy()
im_rgba.putalpha(im_a_blur)
im_rgba_crop = im_rgba.crop((135, 45, 265, 175))
im_rgba_crop.save('data/dst/pillow_putalpha_circle_blur.png')


In [8]:
im_a = Image.open('data/src/horse_r.png').convert('L').resize(im_rgb.size)


In [9]:
im_rgba = im_rgb.copy()
im_rgba.putalpha(im_a)
im_rgba.save('data/dst/pillow_putalpha_horse.png')