How to rotate image around custom point in Pillow?

Learn how to rotate images around a custom center point in Python’s Pillow library using the rotate() function’s center parameter.

how to rotate custom point image

Pillow rotate image

To rotate an image around a custom point, adjust the rotation’s pivot by specifying new coordinates. This is basically to change the center of the image to the different coordinates.

See also  How to rename image files in a folder all to another extension?

By default, Image.rotate() rotates around the image’s center; specify the center parameter to rotate around custom coordinates for precise pivot point control.

from PIL import Image

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

rotated_image = my_image.rotate(180, center=(500, 500))
rotated_image.show()

The center parameter accepts a tuple (x, y) specifying pixel coordinates for the rotation pivot point, where (0, 0) is the top-left corner of the image.

See also  How to rotate a matrix with Numpy

Use the center=(x, y) parameter in Image.rotate() to define custom rotation pivot points, enabling precise control over where images rotate around on the canvas.