A map whose bbox does not match its canvas aspect ratio renders with white bands along two edges — the most common cause of dead space in a saved map. This pads the shorter dimension until the box matches the canvas, then adds a small margin so features never touch the frame.
Geographic versus projected input
In a geographic CRS a degree of longitude is shorter than a degree of
latitude by cos(latitude), so the ratio of coordinate spans is not the
ratio of ground distances and the correction is required. In a projected CRS
the coordinates are already linear and applying it would skew the result.
The branch is taken from the CRS rather than offered as an argument, because the two implementations this replaces each hardcoded one answer and neither knew the other case existed. A bbox with an unknown CRS is treated as projected — the coordinates are all that is known, so use them as given.
The correction uses the mid-latitude, so it is exact only there. Over a box a
few degrees tall that is immaterial; over one spanning tens of degrees it is
not — cos() runs from 0.71 to 0.34 between 45N and 70N — and no single
scalar can be right for the whole extent. Project the data before framing it
if the extent is that large, which is what a map at that scale wants anyway.
