用python简单处理图片(3):添加水

发布时间:2019-08-27 08:06:36编辑:auto阅读(1969)

    一、添加文字水印

    复制代码
    from PIL import Image, ImageDraw,ImageFont
    im = Image.open("d:/pic/lena.jpg").convert('RGBA')
    txt=Image.new('RGBA', im.size, (0,0,0,0))
    fnt=ImageFont.truetype("c:/Windows/fonts/Tahoma.ttf", 20)
    d=ImageDraw.Draw(txt)
    d.text((txt.size[0]-80,txt.size[1]-30), "cnBlogs",font=fnt, fill=(255,255,255,255))
    out=Image.alpha_composite(im, txt)
    out.show()
    复制代码

    二、添加小图片水印

    复制代码
    from PIL import Image
    im = Image.open("d:/pic/lena.jpg")
    mark=Image.open("d:/logo_small.gif")
    layer=Image.new('RGBA', im.size, (0,0,0,0))
    layer.paste(mark, (im.size[0]-150,im.size[1]-60))
    out=Image.composite(layer,im,layer)
    out.show()
    复制代码

关键字