def replaced_box_height(box):
    """Compute and set the used height for replaced boxes."""
    # https://www.w3.org/TR/CSS21/visudet.html#inline-replaced-height
    width, height, ratio = box.replacement.get_intrinsic_size(
        box.style['image_resolution'], box.style['font_size'])

    # Test 'auto' on the computed width, not the used width
    if box.height == box.width == 'auto':
        box.height = height
    elif box.height == 'auto' and ratio:
        box.height = box.width / ratio

    if box.height == box.width == 'auto' and height is not None:
        box.height = height
    elif ratio is not None and box.height == 'auto':
        box.height = box.width / ratio
    elif box.height == 'auto' and height is not None:
        box.height = height
    elif box.height == 'auto':
        # It's pretty useless to rely on device size to set width.
        box.height = 150
Compute and set the used height for replaced boxes.
weasyprint/layout/replaced.py