from PIL import Image # Import Image class from the library. image = Image.open("file.jpg") # Load the image. rotated_image = image.rotate(180) # Rotate the image by 180 degrees. rotated_image.save("file_rotated.jpg") # Save the rotated image.