PIL combine paste image

2018-07-20  本文已影响36人  ShawnDu
from PIL import Image
img = Image.open('avatar.png', 'r')
img_w, img_h = img.size
background = Image.new('RGBA', (1440, 900), (255, 255, 255, 255))
bg_w, bg_h = background.size
offset = ((bg_w - img_w) // 2, (bg_h - img_h) // 2)
img1 = Image.open('splash.png', 'r')
img1_w, img1_h = img1.size
offset1 = ((bg_w - img1_w) // 2, (bg_h - img1_h) // 2)
background.paste(img1, offset1)
r,g,b,a = img.split()
# 如果split函数报错,直接写死透明度
background.paste(img, offset, mask = a) 
background.save('out.png')
上一篇下一篇

猜你喜欢

热点阅读