pip install pillow
from PIL import Image, ImageDraw, ImageFont img_name = '1.jpg' text = '博客园 @三个零' img = Image.open(img_name) draw = ImageDraw.Draw(img) # 选择 字体文件 和 大小 font = ImageFont.truetype('simsun.ttc', 40) # 字体颜色 color = 'aqua' # 添加文字水印 draw.text((img.size[0] - 300, img.size[1] - 60), text, font=font, fill=color) # 保存为新文件 img.save('draw_' + img_name)
from PIL import Image # 需要加水印的图片 img = Image.open('1.jpg') # 水印图片 logo = Image.open('logo.jpg') # 图层 layer = Image.new('RGBA', img.size, (255, 255, 255, 0)) layer.paste(logo, (img.size[0] - logo.size[0], img.size[1] - logo.size[1])) # 覆盖 img_res = Image.composite(layer, img, layer) img_res.save('img_logo.jpg')