def wrap_text (text, font, base_width):
    """Wraps given text into multiple lines to fit into the given width

    Breaks the given text into a list of lines, so that the text when
    rendered with font won't horizontally overflow beyond base_width.
    If possible, lines are broken after complete words.

    Args:
        text (str): The text which is to be wrapped
        font (ImageFont): The font with which the text is to be rendered
        base_width (int): The maximum width for a single line

    Returns:
        list: List of lines
    """

    line_width = 0
    lines = []
    string = ""
    for c in text:
        line_width += font.getsize(c)[0]
        string += c
        if line_width > base_width:
            s = string.rsplit(" ", 1)

            string = s[0]
            lines.append(string)

            try:
                string = s[1]
                line_width = len(string) * 5
            except:
                string = ""
                line_width = 0

    if string:
        lines.append(string)
    return lines