第 1题: 在图片右上角加上红色的数字,类似于微信未读信息数量那种提示效果。
#!/usr/bin/env python3
# -*- coding : utf-8 -*-
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
def addnumtoImage(imagepath,num):
img = Image.open(imagepath)
myfont = ImageFont.truetype("C:\Windows\Fonts\calibri.ttf",24)
width,height = img.size
draw = ImageDraw.Draw(img)
draw.text((width * 0.9,width * 0.07),num,font = myfont,fill = (0xff,0,0))
img.save('result.jpg')
# img.show()
if __name__ == '__main__':
image = input("Please enter filepath:")
addnum = input("please enter a num: ")
addnumtoImage(image,addnum)