from PIL import Image, ImageDraw, ImageFont
class addWaterMask:
def __init__(self):
self.font = ImageFont.truetype("simsun.ttc",30) # 选择字体和大小
def process(self, img_path, text):
img = Image.open(img_path)
draw = ImageDraw.Draw(img)
w,h = draw.textsize(text,self.font)
position = (img.width-w-10, img.height-h-10) # 增加水印位置,
draw.text(position, text, font=self.font, fill=(255,255,255))
return img
test = addWaterMask()
img_path = "1159870977.jpg"
water_mask = "test test 增加水印"
image = test.process(img_path, water_mask)
image.save('test.jpg')
print('done')
python 在图片指定位置添加水印
最新推荐文章于 2024-07-10 05:36:11 发布