python 模拟自己的手写字体

方式一

1.首先去这个网站(萝卜工坊:专属字体制作)生成自己的字体文件(ttf格式的文件)

系统自带的字体文件在:C:\Windows\Fonts

2.通过代码实现手写字体:

# coding: utf-8
from PIL import Image, ImageFont

from handright import Template, handwrite

text = "你好,世界"

template = Template(
    background=Image.new(mode="1", size=(900, 1000), color=1),
    font=ImageFont.truetype("C:/Windows/Fonts/STLITI.TTF", size=100),
    # line_spacing=150,
    # fill=0,  # 字体“颜色”
    # left_margin=100,
    # top_margin=100,
    # right_margin=100,
    # bottom_margin=100,
    # word_spacing=15,
    # line_spacing_sigma=6,  # 行间距随机扰动
    # font_size_sigma=20,  # 字体大小随机扰动
    # word_spacing_sigma=3,  # 字间距随机扰动
    # end_chars=",。",  # 防止特定字符因排版算法的自动换行而出现在行首
    # perturb_x_sigma=4,  # 笔画横向偏移随机扰动
    # perturb_y_sigma=4,  # 笔画纵向偏移随机扰动
    # perturb_theta_sigma=0.05,  # 笔画旋转偏移随机扰动
)
images = handwrite(text, template)
for i, im in enumerate(images):
    assert isinstance(im, Image.Image)
    im.show()
    # im.save(r"C:\Users\zhichao\{}.webp".format(i))

 效果:

 感觉不好看,换了几个字体了也一样。

方式二

from requests import get


text = "hello,world"
params = {
    'text': text,
}

if len(text) > 1035:
    print('The content you entered is too long.')
else:
    try:
        res = get('https://pywhatkit.herokuapp.com/handwriting', params=params)
        with open('text.png', 'wb') as f:
            f.write(res.content)
        print('Successful production.')
    except Exception as e:
        print('Error :', e)

效果:

该方式貌似只支持英文。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Zhichao_97

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

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

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

打赏作者

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

抵扣说明:

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

余额充值