def constrain_size(image_size, new_size):
    """
    Take the biggest integer in the 2-item sequence
    and constrain on that integer.
    """
    w, h = new_size
    max_size = max(new_size)
    ow, oh = image_size
    if oh and ow:
        ow = float(ow)
        if w == max_size or h == '0':
            h = oh / ow * w
        else:
            w = h / (oh / ow)
    return int(w), int(h)
