基于python生成手写的笔记

博客并没有其他网站的号,未经允许不得私自转发

觉得不错,可以关注公众号:小白学习教程,

需要第三方库

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))   ## 生成的图片

生成的图片如下,字迹可以改
在这里插入图片描述

  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jun_军

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值