def canvas_rect(dw, dh):
    """Resizes a canvas dimensions so that it better fits on client browser."""
    ar = dw / dh
    h = 400 if ar > 3 else 500
    w_min = 300
    w_max = 1000
    w = int(ar * h)
    if w > w_max:
        w = w_max
    if w < w_min:
        w = w_min
    return w, h
