A black-and-white photo is a grid of brightness values. image[r][c] — or image[r, c] once it's an array — is row r, column c, with row 0 at the top and column 0 on the left.
A photo app makes thumbnails in two steps:
top, column left, and it is height rows tall and width columns wide.flip:flip | what happens to the cut-out piece |
|---|---|
"none" | nothing |
"left-right" | left and right swap: each row is reversed |
"top-bottom" | top and bottom swap: the order of the rows is reversed |
Task: write thumbnail(image, top, left, height, width, flip) and return the finished piece as a list of lists (if you use NumPy, .tolist() turns an array back into one). The rectangle always fits inside the photo.
Example