Python 实现文字转为图片

话不多说直接上代码

#先导入所需的包
import pygame
import os

pygame.init()  #  初始化

B = '请依次点击 "你" "好" "啊"'         #  变量B需要转图片的文字

text = u"{0}".format(B)           #  引号内引用变量使用字符串格式化

#设置字体大小及路径
font = pygame.font.Font(os.path.join("/Users/akun/Library/Fonts", "msyh.ttf"), 26)
#设置位置及颜色
rtext = font.render(text, True, (0, 0, 0), (255 ,255 ,255))

#保存图片及路径
pygame.image.save(rtext, "p.png")

猜你喜欢

转载自blog.csdn.net/weixin_43843287/article/details/84886661