Let’s learn how to rotate image around custom point in Pillow.
Pillow rotate image
To rotate an image around custom point you just need to move the center of image to the different point. This is basically to change the center of the image to the different coordinates.
By default the rotate is around the left upper point of an image. By parameter you are able to set a new coordinates.
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()
Center parameter set a new center coordinates 500 right and 500 down.
Key Takeaways
- To rotate an image around custom point in Pillow, you can use the following code:
- The `Image.rotate()` method takes two parameters: the angle of rotation and the center of rotation.
- The `center` parameter is a tuple of two numbers that represent the x and y coordinates of the center of rotation.
- The `show()` method displays the image in a new window.
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()
FAQ
- Q: What is the `my_image` variable?
- A: The `my_image` variable is an Image object that represents the image to be rotated.
- Q: What is the `rotated_image` variable?
- A: The `rotated_image` variable is an Image object that represents the rotated image.
- Q: What is the purpose of the `show()` function?
- A: The `show()` function displays the image in a new window.