python3下的PIL叫做 pillow
python -m pip install pillow
创建目录 fonts,把微软雅黑字体放到下面。msyh.ttf
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from PIL import Image,ImageFont,ImageDraw
l = [1,23,4]
text = u"这是一段测试文本,test 123。{}\n ".format(l[1])
im = Image.new("RGB", (300, 50), (255, 255, 255))
dr = ImageDraw.Draw(im)
font = ImageFont.truetype(os.path.join("fonts", "msyh.ttf"), 14)
dr.text((10, 5), text, font=font, fill="#000000")
im.show()
im.save("t.png")
转载于:https://blog.51cto.com/hequan/1899899