文字列表转图片

from PIL import Image, ImageDraw, ImageFont

# 创建一个新的白色图片
width, height = 2481, 3507
image = Image.new('RGB', (width, height), color = (255, 255, 255))

# 准备画笔
draw = ImageDraw.Draw(image)

# 选择字体和大小
font = ImageFont.truetype("/usr/share/fonts/simsun.ttc", 120)
font2 = ImageFont.truetype("/usr/share/fonts/simsun.ttc", 100)
# 写入文字 20长度
text = "120关于议题《所发生的方式的发生的发送到发送到托付给人生巅峰书房宜》附件"
text_position = (20, 20)  # 文字的位置
draw.text(text_position, text, font=font, fill=(0, 0, 0))

text = "1.这里是第哒哒哒哒哒哒多多多多多顶顶顶顶二行非法"
text_position = (100, 220)  # 文字的位置 23长度
draw.text(text_position, text, font=font2, fill=(0, 0, 0))

text = "2.这里是第三行"
text_position = (100, 420)  # 文字的位置
draw.text(text_position, text, font=font2, fill=(0, 0, 0))

text = "3.这里是第四行"
text_position = (100, 620)  # 文字的位置
draw.text(text_position, text, font=font2, fill=(0, 0, 0))

# 保存图片
image.save('hello.jpg')

print("图片已保存")

120 大小 20个字

100 大小 23个字

发表回复