在图片右上角添加数字的Python代码
此代码可以在图片右上角添加一个数字提示,类似于微信的未读消息样式
from PIL import Image, ImageDraw, ImageFont def add_num(picPath, num): img = Image.open(picPath) x, y = img.size myfont = ImageFont.truetype('Futura.ttf', x / 3) ImageDraw.Draw(img).text((2 * x / 3, 0), str(num), font = myfont, fill = 'red') img.save('pic_with_num.jpg') if __name__ == '__main__': add_num('pidancodec.om.jpg', 23)
相关文章