python 模拟自己的手写字体
生活随笔
收集整理的這篇文章主要介紹了
python 模拟自己的手写字体
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
方式一
1.首先去這個網(wǎng)站(蘿卜工坊:專屬字體制作)生成自己的字體文件(ttf格式的文件)
系統(tǒng)自帶的字體文件在:C:\Windows\Fonts
2.通過代碼實現(xiàn)手寫字體:
# coding: utf-8 from PIL import Image, ImageFontfrom handright import Template, handwritetext = "你好,世界"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=",。", # 防止特定字符因排版算法的自動換行而出現(xiàn)在行首# perturb_x_sigma=4, # 筆畫橫向偏移隨機擾動# perturb_y_sigma=4, # 筆畫縱向偏移隨機擾動# perturb_theta_sigma=0.05, # 筆畫旋轉(zhuǎn)偏移隨機擾動 ) 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 gettext = "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)效果:
該方式貌似只支持英文。。。
總結(jié)
以上是生活随笔為你收集整理的python 模拟自己的手写字体的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [jQuery] jQuery的队列是如
- 下一篇: [vue] watch的属性用箭头函数定