457475451 发表于 2018-8-15 10:13:01

python3 文本变图片

#!/usr/bin/env python  
# -*- coding: utf-8 -*-
  
import os
  
fromPILimport   Image,ImageFont,ImageDraw
  
l =
  
text = u"这是一段测试文本,test 123。{}\n ".format(l)
  
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")
页: [1]
查看完整版本: python3 文本变图片