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, uses the Pillow library's Image and ImageOps modules to rotate the image by the specified angle, and saves the rotated image in the current directory.
Technology Stack : Pillow library (Python Imaging Library)
Code Type : Image processing
Code Difficulty : Intermediate
def rotate_image(image_path, angle):
from PIL import Image, ImageOps
# Open the image file
with Image.open(image_path) as img:
# Rotate the image
rotated_img = ImageOps.rotate(img, angle)
# Save the rotated image
rotated_img.save("rotated_" + image_path)