美文网首页
PIL combine paste image

PIL combine paste image

作者: ShawnDu | 来源:发表于2018-07-20 11:48 被阅读36次
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')

相关文章

网友评论

      本文标题:PIL combine paste image

      本文链接:https://www.haomeiwen.com/subject/pgvfmftx.html