Live2D

Python之图片批量添加水印

from PIL import Image,ImageDraw,ImageFont
image = Image.open("./image/6.png")
text = "哈哈"
text1 = "鸟叔"
#添加字体样式
font = ImageFont.truetype('./zi/STXIHEI.TTF',25)
#将图片转换成RGBA形式
layer = image.convert('RGBA')
#添加透明度
text_overlay = Image.new('RGBA',layer.size,(255,255,255,0))
image_draw = ImageDraw.Draw(text_overlay)
text_size_x,text_size_y = image_draw.textsize(text,font = font)
#选择水印位置
text_xy = (layer.size[0] - text_size_x,layer.size[1] - text_size_y)
text_xy1 = (0,layer.size[1] - text_size_y)
#将确定的字体颜色以及样式添加上去
image_draw.text(text_xy,text,font=font,fill=(255,255,155,255))
image_draw.text(text_xy1,text1,font=font,fill=(255,255,155,255))
after = Image.alpha_composite(layer,text_overlay)
#生成新图片
after.save("./image/25.png")
#当然也可以将图片作为水印弄到图片上,步骤差不多,只不过将文字换成图片先读取,然后添加即可
#批量的话加入循环即可

 

 

 

 

 

 
posted @ 2020-08-07 10:40  鸟-叔  阅读(670)  评论(0编辑  收藏  举报