第 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)
效果如图:
本文介绍了一个简单的Python脚本,该脚本使用PIL库在图片的右上角添加类似微信未读消息计数器的红色数字提示。通过指定字体、大小及位置,实现了自定义的视觉效果。
1万+

被折叠的 条评论
为什么被折叠?



