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()
原图:
水印:
添加水印后:
本文来自博客园,作者:方倍工作室,转载请注明原文链接:https://www.cnblogs.com/txw1958/archive/2012/07/20/python3-watermark.html