Python图片添加水印修改MD5值
效果图


安装pillow(python图形界面库)
pip install pillow
试了好几次了不知道为什么总数装到一半报错
看到一位朋友发的可以用豆瓣提供的源 pip install -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com pillow
亲测可以使用
生成水印
from PIL import Image,ImageDraw,ImageFont
# 生成水印
# @filename 文件路径 @text 水印文本内容
def generateMark(filename, text):
# 实例化图片对象
img = Image.open(filename)
w, h = img.size # 获取图片的宽、高,以便计算图片的相对位置
fontSize = int(min(w,h) / 15)
distX = w/2 - fontSize * len(text) / 4
distY = h - fontSize * 2
readAppend(filename, "before ")
# 设置字体、字体大小
font = ImageFont.truetype("./font/STXINGKA.TTF", fontSize)
draw = ImageDraw.Draw(img)
draw.text(xy=(distX, distY), text=text, fill=(0, 255, 255), font=font)
# 保存文件
tempPath =