python 模拟自己的手写字体
生活随笔
收集整理的這篇文章主要介紹了
python 模拟自己的手写字体
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
方式一
1.首先去這個(gè)網(wǎng)站(蘿卜工坊:專(zhuān)屬字體制作)生成自己的字體文件(ttf格式的文件)
系統(tǒng)自帶的字體文件在:C:\Windows\Fonts
2.通過(guò)代碼實(shí)現(xiàn)手寫(xiě)字體:
# 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, # 行間距隨機(jī)擾動(dòng)# font_size_sigma=20, # 字體大小隨機(jī)擾動(dòng)# word_spacing_sigma=3, # 字間距隨機(jī)擾動(dòng)# end_chars=",。", # 防止特定字符因排版算法的自動(dòng)換行而出現(xiàn)在行首# perturb_x_sigma=4, # 筆畫(huà)橫向偏移隨機(jī)擾動(dòng)# perturb_y_sigma=4, # 筆畫(huà)縱向偏移隨機(jī)擾動(dòng)# perturb_theta_sigma=0.05, # 筆畫(huà)旋轉(zhuǎn)偏移隨機(jī)擾動(dòng) ) 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))?效果:
?感覺(jué)不好看,換了幾個(gè)字體了也一樣。
方式二
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 模拟自己的手写字体的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: [jQuery] jQuery的队列是如
- 下一篇: python ImportError: