博客并没有其他网站的号,未经允许不得私自转发
觉得不错,可以关注公众号:小白学习教程,
需要第三方库
PIL,Image,ImageFont,python-docx,handright
from PIL import Image, ImageFont
import docx
from handright import Template, handwrite
text=""
file = docx.Document(r".\笔记.docx") ##word路径
for pare in file.paragraphs:
text =text +'\n' + str(pare.text)
print(text)
template = Template(
background = Image.open(r".\22.jpg"), ## 需要手动拍摄一张图片
font_size=40,
font=ImageFont.truetype(r".\MILanProVF-Thin.ttf"), ##字体
line_spacing=50,
fill=0,
left_margin=100,
top_margin=100,
right_margin=100,
bottom_margin=100,
word_spacing=2,
line_spacing_sigma=0,
font_size_sigma=2,
word_spacing_sigma=2,
end_chars=", :",
perturb_x_sigma=4,
perturb_y_sigma=4,
perturb_theta_sigma=0.05,
)
image =handwrite(text,template)
for i ,im in enumerate(image):
assert isinstance(im,Image.Image)
im.save("./1.jpg".format(i)) ## 生成的图片
生成的图片如下,字迹可以改