You can download this code by clicking the button below.
This code is now available for download.
This function takes an image path and an angle as parameters, rotates the image by the specified angle, and saves it to a new file.
Technology Stack : Pillow
Code Type : Image processing
Code Difficulty : Intermediate
def rotate_image(image_path, angle):
from PIL import Image
# Open the image file
with Image.open(image_path) as img:
# Rotate the image
rotated_img = img.rotate(angle)
# Save the rotated image
rotated_img.save("rotated_" + image_path)