MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / create_font

Function create_font

tools/infer/utility.py:81–92  ·  view source on GitHub ↗
(txt, sz, font_path='./doc/fonts/simfang.ttf')

Source from the content-addressed store, hash-verified

79
80
81def create_font(txt, sz, font_path='./doc/fonts/simfang.ttf'):
82 font_size = int(sz[1] * 0.99)
83 font = ImageFont.truetype(font_path, font_size, encoding='utf-8')
84 if int(PIL.__version__.split('.')[0]) < 10:
85 length = font.getsize(txt)[0]
86 else:
87 length = font.getlength(txt)
88
89 if length > sz[0]:
90 font_size = int(font_size * sz[0] / length)
91 font = ImageFont.truetype(font_path, font_size, encoding='utf-8')
92 return font
93
94
95def draw_box_txt_fine(img_size, box, txt, font_path='./doc/fonts/simfang.ttf'):

Callers 1

draw_box_txt_fineFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected