def add_borders(Figs, titles, border_color='#000000', text_color='#800080', con_id=""):

    """
    Formatting for generating plots on the server
    Default border color: black
    Default text color: purple
    """
    def split_title(s):
        """
        Add '\n's to split of overly long titles
        """
        s_list = s.split(",")
        lines = []
        tot = 0
        line = []
        for i in s_list:
            tot += len(i)
            if tot < 30:
                line.append(i + ",")
            else:
                lines.append(" ".join(line))
                line = [i]
                tot = 0
        lines.append(" ".join(line))
        return "\n".join(lines).strip(',')

    # format contribution id if available
    if con_id:
        if not str(con_id).startswith("/"):
            con_id = "/" + str(con_id)

    import datetime
    now = datetime.datetime.utcnow()

    for key in list(Figs.keys()):

        fig = plt.figure(Figs[key])
        plot_title = split_title(titles[key]).strip().strip('\n')
        fig.set_figheight(5.5)
        #get returns Bbox with x0, y0, x1, y1
        pos = fig.gca().get_position()
        # tweak some of the default values
        w = pos.x1 - pos.x0
        h = (pos.y1 - pos.y0) / 1.1
        x = pos.x0
        y = pos.y0 * 1.3
        # set takes: left, bottom, width, height
        fig.gca().set_position([x, y, w, h])

        # add an axis covering the entire figure
        border_ax = fig.add_axes([0, 0, 1, 1])
        border_ax.set_frame_on(False)
        border_ax.set_xticks([])
        border_ax.set_yticks([])
        # add a border
        if "\n" in plot_title:
            y_val = 1.0  # lower border
            #fig.set_figheight(6.25)
        else:
            y_val = 1.04  # higher border
        #border_ax.text(-0.02, y_val, "                                                                                                   #                                                                                      |",
        #               horizontalalignment='left',
        #               verticalalignment='top',
        #               color=text_color,
        #               bbox=dict(edgecolor=border_color,
        #                         facecolor='#FFFFFF', linewidth=0.25),
        #               size=50)
        #border_ax.text(-0.02, 0, "|                                                                                                      #                                                                                   |",
        #               horizontalalignment='left',
        #               verticalalignment='bottom',
        #               color=text_color,
        #               bbox=dict(edgecolor=border_color,
        #                         facecolor='#FFFFFF', linewidth=0.25),
        #               size=20)#18)

        # add text

        border_ax.text((4. / fig.get_figwidth()) * 0.015, 0.03, now.strftime("%Y-%m-%d, %I:%M:%S {}".format('UT')),
                       horizontalalignment='left',
                       verticalalignment='top',
                       color=text_color,
                       size=10)
        border_ax.text(0.5, 0.98, plot_title,
                       horizontalalignment='center',
                       verticalalignment='top',
                       color=text_color,
                       size=20)
        border_ax.text(1 - (4. / fig.get_figwidth()) * 0.015, 0.03, 'earthref.org/MagIC{}'.format(con_id),
                       horizontalalignment='right',
                       verticalalignment='top',
                       color=text_color,
                       size=10)
    return Figs
Formatting for generating plots on the server
    Default border color: black
    Default text color: purple