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

歡迎訪問 生活随笔!

生活随笔

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

python

python 模拟自己的手写字体

發(fā)布時間:2023/12/9 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)容,希望文章能夠幫你解決所遇到的問題。

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