A photo classifier was built for inputs of one fixed size, but the photos people upload arrive in every shape. This pipeline never stretches a photo to fit (that would squash a tall photo into a wide one). It fixes the height and the width separately, each with one of two moves:
When the difference is odd it can't split evenly. Then the top (for rows) or left (for columns) side gets the smaller share and the bottom or right side gets the extra one. This rule is the same whether you are adding zeros or cutting pixels. For example, fitting a photo 7 columns wide into 4 columns removes 3 columns: 1 from the left and 2 from the right.
A photo can be too tall and too narrow at the same time. Then rows are cut and columns are added.
Task: write fit_to_frame(image, height, width).
image is a grayscale photo: a list of rows, each a list of pixel values from 0 to 255. Every row has the same length.height rows and width columns, built by the rules above.height and width are at least 1.