# 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/simfang.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()
python代码模拟 手写字体
最新推荐文章于 2024-05-06 15:51:15 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)