Week 6

CS50 P-Shirt

Open a photo, fit it to the shirt's size, and lay the shirt on top.

You type

An input image and an output image, after the program name.

The tool
Fit the photo, then lay the shirt on it Open both images Fit the photo Lay the shirt on top
What comes out

A new image. Bad arguments, or a missing file, stop the program.

The question, more slowly

The question is: two image paths on the command line, input and output. They must be images with the same extension. The input must exist. You resize and crop the photo to the shirt's size, paste the shirt using its transparent background, and save the result.

The spec names the Pillow calls, in order: open, fit, paste, save. It also tells you where to download the shirt and the sample photos. Follow that order. The paste uses the shirt as its own mask so the transparent pixels do not paint over the face.

People resize without cropping, so the shirt does not sit right, or they accept two different extensions. The spec says the extensions must match.

Before you code

The spec names the image calls and includes the shirt picture. Read those steps in order before you write them down in code.