def get_position_by_shortcut(shortcut, base_size, overlay_size):
    """ returns tuple (x, y) to paste overlay_size into base_size image by shortcut
    for example BaseImage.paste(OverlayImage, (x, y))
    allowed shortcuts:
    c - center
    l - left
    r - right
    t - top
    b - bottom
    and combinations lt, tl, lb, bl, rt, tr, rb, br
    """
    w, h = base_size
    w_o, h_o = overlay_size

    positions = {}
    c = (int(w / 2) - int(w_o / 2), int(h / 2) - int(h_o / 2))
    positions['c'] = c
    positions['l'] = (0, c[1])
    positions['r'] = (w - w_o, c[1])
    positions['t'] = (c[0], 0)
    positions['b'] = (c[0], h - h_o)

    # For combinations of left/rigth and top/bottom
    for x in ('l', 'r'):
        for y in ('t', 'b'):
            positions[x + y] = (positions[x][0], positions[y][1])
            positions[y + x] = positions[x + y]

    position = positions.get(shortcut)
    if not position:
        raise Exception('Ambiguous shortcut for position - %s' % shortcut)
    return position