python3给图片添加水印

#!/usr/local/bin/python3
#coding=gbk

import os, io, sys, re, time, json, random
from PIL import Image, ImageEnhance, ImageFilter

def watermark(img_source, img_water, img_new, offset_x, offset_y):
    try:
        im = Image.open(img_source)
        wm = Image.open(img_water)
        layer = Image.new('RGBA', im.size, (0,0,0,0))
        layer.paste(wm, (im.size[0] - offset_x, im.size[1] - offset_y))
        newIm = Image.composite(layer, im, layer)
        newIm.save(img_new)

    except Exception as e:
        print(">>>>>>>>>>> WaterMark EXCEPTION:  " + str(e))
        return False
    else:
        return True

def main():
    watermark("original.jpg", "watermark.png", "afterwater.jpg", 250, 50)

if __name__ == '__main__':
    main()

 

原图:

python3给图片添加水印

 

水印:

python3给图片添加水印

 

添加水印后:

python3给图片添加水印

上一篇:用SpriteBuilder简化"耕牛遍地走"的动画效果(三)


下一篇:python发邮件实例(包括:文本、html、图片、附件、SSL、群邮件)