def get_thumbnail_spec(size, height):
    """
    Get the source rectangle (x, y, x + w, y + h) and result size (w, h) for
    the thumbnail of the specified height of an image with the specified size.
    """
    size_width, size_height = size

    max_source_width = 2 * max(size_height, height)
    max_source_height = max(2 * size_width, height)

    source_width = min(size_width, max_source_width)
    source_height = min(size_height, max_source_height)
    source_left = (size_width - source_width) // 2
    source_top = 0

    result_height = min(size_height, height)
    result_width = (source_width * result_height + source_height // 2) // source_height

    return (
        (source_left, source_top, source_left + source_width, source_top + source_height),
        (result_width, result_height),
    )