How to rotate image in Pillow?

Let’s see how to rotate image in Pillow Python library.
python meme to rotate

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()

python pillow image rotate 180 angle

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 (\).

See also  How to rotate a matrix with Numpy

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.

See also  How to rotate image around custom point in Pillow?

Python Pillow rotate image custom angle

Rotating the image by custom angle

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.

from PIL import Image

my_image = Image.open("C:/Users/pythoneo/Documents/image.jpg")

rotated_image = my_image.rotate(80, expand=True)
rotated_image.show()