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)
最后
以上就是神勇冰淇淋最近收集整理的关于python 在图片右上角添加红色数字的全部内容,更多相关python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复