python 图像加水印
from PIL import Image,ImageDraw,ImageFont
image = Image.open("/data_2/dog1.jpg")
text = "仅供授权证明用,他用无效 \n有效期:20210401-20210430"
font=ImageFont.truetype("/data_1/data_1T-2-ok/Yang/software/window-fonts/simhei.ttf", 60) #/data_1/data_1T-2-ok/Yang/software/window-fonts/simfang.ttf
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-20)
image_draw.text(text_xy,text,font=font,fill=(25,255,155,200))
font=ImageFont.truetype("/data_1/data_1T-2-ok/Yang/software/window-fonts/simfang.ttf", 85) #
text_xy = (0,0)
image_draw.text(text_xy,text,font=font,fill=(5,25,255,250))
font=ImageFont.truetype("/data_1/Yang/software/window-fonts/xingkai.ttf", 70) #
text_xy = (layer.size[1]*0.15,layer.size[1]/2.0)
image_draw.text(text_xy,text,font=font,fill=(50,120,25,180))
after = Image.alpha_composite(layer,text_overlay)
after.show()
after.convert('RGB').save("/data_1/everyday/0401/22.jpg")
好记性不如烂键盘---点滴、积累、进步!