Skip to content

Commit 424fd03

Browse files
committed
pinyin and glyph
1 parent fce7b8e commit 424fd03

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
@file : image_test.py
3+
@author : xiaolu
4+
@email : luxiaonlp@163.com
5+
@time : 2021-07-22
6+
"""
7+
import os
8+
import pygame
9+
chinese_dir = 'chinese'
10+
if not os.path.exists(chinese_dir):
11+
os.mkdir(chinese_dir)
12+
13+
pygame.init()
14+
start, end = (0x4E00, 0x9FA5)#汉字编码范围
15+
for codepoint in range(int(start), int(end)):
16+
word = chr(codepoint)
17+
font = pygame.font.Font("MSYH.TTC", 22)#当前目录下要有微软雅黑的字体文件msyh.ttc,或者去c:\Windows\Fonts目录下找
18+
rtext = font.render(word, True, (0, 0, 0), (255, 255, 255))
19+
pygame.image.save(rtext, os.path.join(chinese_dir,word+".png"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
@file : pinyin_test.py
3+
@author : xiaolu
4+
@email : luxiaonlp@163.com
5+
@time : 2021-07-22
6+
"""
7+
from pypinyin import pinyin, lazy_pinyin, Style
8+
9+
if __name__ == '__main__':
10+
print(pinyin('新浪微博')) # 输出: [['xīn'], ['làng'], ['wēi'], ['bó']]
11+
12+
print(lazy_pinyin('新浪微博')) # 输出: ['xin', 'lang', 'wei', 'bo']
13+
14+
# 将拼音用数字表示 然后跟在拼音的后面
15+
style = Style.TONE3 # 1代表一声、2代表二声、3代表三声、4代表四声
16+
print(lazy_pinyin('新浪微博', style=style))
17+

0 commit comments

Comments
 (0)