python文字转图片

from PIL import Image, ImageFont, ImageDraw


def CreateImg(text):
    fontSize = 30
    liens = text.split('\n')
    print(len(liens))
    im = Image.new("RGB", (480, len(lines)*(fontSize+5)), (255, 0, 0))
    dr = ImageDraw.Draw(im)
    fontPath = r"C:\Windows\Fonts\STKAITI.TTF"
    # font = ImageFont.truetype(r"C:\Windows\Fonts\AdobeHeitiStd-Regular.otf", 25)
    font = ImageFont.truetype(fontPath, fontSize)
    dr.text((0, 0), text, font=font, fill="#FFFF00")
    im.save('output.png')
    im.show()

你可能感兴趣的:(python文字转图片)