日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python 模拟自己的手写字体

發(fā)布時(shí)間:2023/12/9 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。