the program should resize the image only if the width or height is larger than square_fit_size ( pixelsin this case)so put all of the resizing code inside an if statement that checks the width and height variables add the following code to your program#python resizeandaddlogo py resizes all images in current working directory to fit in squareand adds catlogo png to the lower-right corner import os from pil import image --snip-check if image needs to be resized if width square_fit_size and height square_fit_sizecalculate the new width and height to resize to if width heightu height int((square_fit_size widthheightwidth square_fit_size elsev width int((square_fit_size heightwidthheight square_fit_size resize the image print('resizing % (filename) im im resize((widthheight)--snip-if the image does need to be resizedyou need to find out whether it is wide or tall image if width is greater than heightthen the height should be reduced by the same proportion that the width would be reduced this proportion is the square_fit_size value divided by the current width the new height value is this proportion multiplied by the current height value since the division operator returns float value and resize(requires the dimensions to be integersremember to convert the result to an integer with the int(function finallythe new width value will simply be set to square_fit_size if the height is greater than or equal to the width (both cases are handled in the else clause)then the same calculation is doneexcept with the height and width variables swapped once width and height contain the new image dimensionspass them to the resize(method and store the returned image object in im step add the logo and save the changes whether or not the image was resizedthe logo should still be pasted to the bottom-right corner where exactly the logo should be pasted depends on both the size of the image and the size of the logo figure - shows how manipulating images