# 绘画库 from PIL import ImageDraw # 字体库 from PIL import ImageFont # 图片库 from PIL import Image
# 图片添加水印 defmake_watermark(file_path, new_name, fonts, size, font_path): ''' :param file_path: the path of your image file, it must be string. :param new_name: The new name of your picture, it must be string. :param fonts: The font that you want to add on your picture,it must be string. :param size: the size of your watermark. :param font_path: The path of your font file. :return: if it could work normally, it will return True, if not,it will return False. ''' try: font = ImageFont.truetype(font_path, size) im = Image.open(file_path) print(im.format, im.size, im.mode) # 生成画笔 draw = ImageDraw.Draw(im) # 绘制 draw.text((0, 0), fonts, fill=(76, 234, 124, 180), font=font) draw = ImageDraw.Draw(im) im.save(new_name) except Exception: returnFalse