话不多说直接上代码
#先导入所需的包
from PIL import ImageFont, Image, ImageDraw
#导入本地字体路径及设置字体大小
font = ImageFont.truetype("/Users/akun/Library/Fonts/msyh.ttf",13)
#打开本地所需图片
imageFile = "captch.png"
im1=Image.open(imageFile)
# 在图片上添加文字
draw = ImageDraw.Draw(im1)
draw.text((0, 0),"你好啊!",(255,255,0),font=font)
draw = ImageDraw.Draw(im1)
im1.save("result.png")