Support latest pillow

This commit is contained in:
kijai 2024-04-07 15:46:06 +03:00
parent 7051d43a4f
commit 051c3fcd9a

View File

@ -741,17 +741,29 @@ creates animation between them.
lines = [] lines = []
current_line = [] current_line = []
current_line_width = 0 current_line_width = 0
try: #new pillow
# Iterate through words to create lines # Iterate through words to create lines
for word in words: for word in words:
word_width = font.getsize(word)[0] left, _, right, _ = font.getbbox(word)
if current_line_width + word_width <= width - 2 * text_x: font_width = right - left
current_line.append(word) word_width = font_width * len(word) # Assuming each character is the same width
current_line_width += word_width + font.getsize(" ")[0] # Add space width if current_line_width + word_width <= width - 2 * text_x:
else: current_line.append(word)
lines.append(" ".join(current_line)) current_line_width += word_width + font_width # Add space width
current_line = [word] else:
current_line_width = word_width lines.append(" ".join(current_line))
current_line = [word]
current_line_width = word_width
except: #old pillow
for word in words:
word_width = font.getsize(word)[0]
if current_line_width + word_width <= width - 2 * text_x:
current_line.append(word)
current_line_width += word_width + font.getsize(" ")[0] # Add space width
else:
lines.append(" ".join(current_line))
current_line = [word]
current_line_width = word_width
# Add the last line if it's not empty # Add the last line if it's not empty
if current_line: if current_line: