python 在图片右上角添加红色数字
Python 练习册,每天一个小程序
第 0000 题: 将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。 类似于图中效果
代码如下:
from PIL
import Image, ImageDraw, ImageFont
def add_num(img):
draw = ImageDraw.Draw(img)
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)