您的位置:首页 > 编程语言 > Python开发

python 在图片右上角添加红色数字

2017-08-06 09:37 281 查看

python 在图片右上角添加红色数字

Python 练习册,每天一个小程序

第 0000 题: 将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。 类似于图中效果

代码如下:

from PIL import Image, ImageDraw, ImageFont
#PIL https://pillow.readthedocs.org/ def add_num(img):
draw = ImageDraw.Draw(img)
#加载TrueType或OpenType字体文件,并创建一个字体对象。
myfont = ImageFont.truetype('C:/windows/fonts/Arial.ttf', size=20)
fillcolor = "#ff0000"
width, height = img.size
draw.text((width-40, 0), '2', font=myfont, fill=fillcolor)
img.save('result.jpg','jpeg')
return 0

image = Image.open('image.jpg')
print(image.format,image.size,image.mode)
add_num(image)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: