#添加文字水印from PIL import Image,ImageFont,ImageDrawa=Image.open("cat.jpg").convert('RGBA')b=Image.new('RGBA',a.size,(0,0,0,0)) #(0,0,0,0)代表透明fnt=ImageFont.truetype("simsun.ttc",40) #设置字体c=ImageDraw.Draw(b) #将新建的图像填入画板c.text((b.size[0]-200,b.size[1]-80),"猫咪老师",font=fnt,fill=(0,0,0))d=Image.alpha_composite(a,b) #合并两个图像d.show()
运行结果:
添加logo水印
#添加logo水印from PIL import Image,ImageFont,ImageDrawa=Image.open("cat.jpg").convert('RGBA') #打开原文件watermark=Image.open("logotext.png").convert("RGBA").resize((100,100)) #打开并转换设置logo水印width,height=a.sizemark_width,mark_height=watermark.sizeposition=(width-mark_width,height-mark_height)b=Image.new('RGBA',(width,height),(0,0,0,0)) #创建新图像:透明b.paste(a,(0,0))b.paste(watermark,position,mask=watermark)b.show()b.szve("figure20.18.png")
运行结果: