Skip to content

Commit

Permalink
Replace deprecated FreeTypeFont.getsize()
Browse files Browse the repository at this point in the history
  • Loading branch information
xslingcn authored and lss233 committed Nov 22, 2023
1 parent a4dfc6e commit 546f248
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions utils/text_to_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ def text_to_image_raw(text, width=config.text_to_image.width, font_name=config.t
lines = text.split('\n')
line_lengths = [draw.textlength(line, font=font) for line in lines]
text_width = max(line_lengths)
text_height = font.getsize(text)[1]
char_width = font.getsize('.')[0]
_, top, _, bottom = font.getbbox(text)
text_height = bottom - top
left, _, right, _ = font.getbbox('.')
char_width = right - left

wrapper = TextWrapper(width=int(width / char_width), break_long_words=True)
wrapped_text = [wrapper.wrap(i) for i in lines if i != '']
Expand Down

0 comments on commit 546f248

Please sign in to comment.