-
I am having problems with Image.transform method=Image.Transform.PERSPECTIVE I thought the 'data' arg was a sequence of 8 (x,y) values indicating the corners of source and destination image, however this is not working. Any suggestions appreciated. Thanks, |
Beta Was this translation helpful? Give feedback.
Answered by
radarhere
May 22, 2022
Replies: 1 comment 3 replies
-
The official documentation is at https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.transform When you say it's not working, what do you mean exactly? Here is code that will rotate one of our test images by 90 degrees. import math
from PIL import Image
im = Image.open("hopper.png")
angle = -math.radians(90)
matrix = [
round(math.cos(angle), 15),
round(math.sin(angle), 15),
0.0,
round(-math.sin(angle), 15),
round(math.cos(angle), 15),
0.0,
0,
0,
]
matrix[2] = (1 - matrix[0] - matrix[1]) * im.width / 2
matrix[5] = (1 - matrix[3] - matrix[4]) * im.height / 2
im.transform(im.size, Image.Transform.PERSPECTIVE, matrix).save("rotated_90.png") |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
radarhere
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The official documentation is at https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.transform
When you say it's not working, what do you mean exactly? Here is code that will rotate one of our test images by 90 degrees.