// Both sides of the image are shorter than the desired dimension,
// so take the side that"s closer in size and enlarge the image
// in both directions to make that one fit
factor = min(ratio_h, ratio_w)
img = img.resize((int(width * factor), int(height * factor)))
// Now we have an image that"s either larger than the desired shape
// or at least one side matches the desired shape and we can resize
// with contain