Skip to content

Instantly share code, notes, and snippets.

View omirete's full-sized avatar
🚀
Automating the boring bits

Federico Giancarelli omirete

🚀
Automating the boring bits
View GitHub Profile
@omirete
omirete / text.py
Last active February 7, 2020 01:31 — forked from Eyongkevin/text_wrap.py
Function to split text into list of sentences where none exceeds a given maximum width, based on the font size.
from PIL import ImageFont
def get_wrapped_text(text, PIL_font, max_width):
# Returns a list where each item is a line of text that does not exceed
# the max_width. If there should be any single word that is bigger than
# the max_width argument, it will be shown in an individual line, even
# though it exceeds the max_width.
lines = []