Python3 + PIL 实现大量文字转图片与自动换行(支持中英文与\t\n) 需求 代码 需求 将传入的长字符串简单地自动排版,并转为png图片 代码 # coding=utf-8 import re from PIL import Image, ImageDraw, ImageFont LINE_CHAR_COUNT = 50*2 # 每行字符数:30个中文字符(=60英文字符) CHAR_SIZE = 30 TABLE_WIDTH = 4 def line_break(line): ret = '' width = 0 for c in line: if len(c.encode('utf8')) ==