Let’s see how to rotate image in Pillow Python library.
Rotating the image
For a start we will rotate image 180 degrees.
from PIL import Image my_image = Image.open("C:/Users/pythoneo/Documents/image.jpg") rotated_image = my_image.rotate(180, expand='True') rotated_image.show()
First, I imported Pillow Python library which does the job.
Next, I identified the path when script can access my_image. Remember to use slashes (/) instead of backslashes (\).
Rotate andgle is the first parameter of rotate Pillow function.
The second recommended parameter is expand method. Better to set it to True to fit an image to the window.
See the example when you rotate image by custom angle. The benefit is that corners of your image fit to the window. This is image rotated 80 angles clockwise.