Python:Pillow .rotate()
Published Jun 20, 2024
Contribute to Docs
In Pillow, the .rotate() method is used to rotate a given image anti-clockwise around its center by a specified number of degrees.
Syntax
Image.rotate(angle, resample=Resampling.NEAREST, expand=0, center=None, translate=None, fillcolor=None)
angle: The angle to rotate the image by in degrees anti-clockwise.resample: The resampling filter to use. Options includeResampling.NEAREST,Resampling.BILINEAR, andResampling.BICUBIC.expand: A boolean that, ifTrue, expands the output image to make sure the whole rotated image fits.center: A tuple(x, y)representing the center of rotation. The default is the upper-left corner.translate: A tuple(x, y)representing post-rotate translation.fillcolor: The color to use for areas outside the rotated image.
Note: The
.rotate()method requires theangleparameter, whileresample,expand,center,translate, andfillcolorare optional parameters for additional control over the rotating process.
Example
The following example demonstrates the use of the .rotate() method:
from PIL import Image# Opening the original imageimg = Image.open('pillow-rotate-earth.png')# Showcasing the original imageimg.show()# Rotating the image by 30 degreesimage_rotated = img.rotate(30)# Showcasing the rotated imageimage_rotated.show()
The above example produces two outputs. Here is the first one:

Here is the second one:

Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Pillow on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours