美文网首页
Python图像上添加数字

Python图像上添加数字

作者: Junetaurus | 来源:发表于2017-12-05 15:33 被阅读0次

图像右上角添加红色的数字,类似于微信未读信息数量提示效果。


初始图片
#-*-coding: utf-8-*-
from PIL import Image, ImageDraw, ImageFont

def imageWriter(filePath, number):
    img = Image.open(filePath)
    size = img.size
    fontSize = size[1] / 4
    draw = ImageDraw.Draw(img)
    ttFont = ImageFont.truetype('ahronbd.ttf', 50)
    draw.text((size[0]-fontSize, 0), str(number),fill=(255, 0, 0) ,font=ttFont)
    img.show()

print(imageWriter('0.png', 8))
运行结果: 效果图

相关文章

网友评论

      本文标题:Python图像上添加数字

      本文链接:https://www.haomeiwen.com/subject/wsjcixtx.html