def _max_factor(n, factor, max_size):
    """ Return the largest factor within the provided max;
    e.g., the most images of size n thet can fit in max_size
    """
    if max_size is None or n * factor <= max_size:
        return factor
    return max_size // n