python pil 给图片添加一个半透明的效果
作者:互联网
from PIL import Image, ImageDraw
bg_img =Image.open('./Morning.png')
# bg_img = Image.new("RGBA", (256, 256), (0, 0, 255, 255))
def drawRect(img, pos, **kwargs):
transp = Image.new('RGBA', img.size, (0,0,0,0))
draw = ImageDraw.Draw(transp, "RGBA")
draw.rectangle(pos, **kwargs)
img.paste(Image.alpha_composite(img, transp))
drawRect(bg_img, (0,155,875,435), fill=(255,255,255,150))
bg_img.show()
这是原图
标签:bg,pil,img,python,Image,transp,RGBA,半透明,255 来源: https://www.cnblogs.com/addPath/p/15857958.html