PIL - 图像不旋转 [英] PIL - Images not rotating
问题描述
我很好奇为什么我的图像没有旋转,它每次都以相同的位置结束.
I'm curious as to why my image is not rotating, it ends up in the same position every time.
img = Image.open(r'C:\Users\Brett\Downloads\testing.jpg')
exif_data = {
TAGS[k]: v
for k, v in img._getexif().items()
if k in TAGS
}
print(exif_data['Orientation'])
输出'6'
无论我告诉图像旋转多少度,它最终都会处于相同的位置.
No matter how many degrees I tell the image to rotate it ends up in the same position.
if exif_data['Orientation'] == 6:
img.rotate(90)
或
if exif_data['Orientation'] == 6:
img.rotate(270)
或
if exif_data['Orientation'] == 6:
img.rotate(180)
我总是得到逆时针旋转 90 度的图像.我做错了什么吗?
I always end up with an image rotated 90 degrees counter-clockwise. Am I doing something obviously wrong?
推荐答案
来自 (DOCS)
Image.rotate(angle, resample=0, expand=0, center=None, translate=None)
Image.rotate(angle, resample=0, expand=0, center=None, translate=None)
返回此图像的旋转副本.此方法返回此图像的副本,围绕其中心逆时针旋转给定的度数.
Returns a rotated copy of this image. This method returns a copy of this image, rotated the given number of degrees counter clockwise around its centre.
图像没有原地旋转.您需要存储从 rotate()
返回的图像.也许是这样的:
The image is not rotated in place. You need to store the image returned from rotate()
. Maybe something like:
if exif_data['Orientation'] == 6:
new_image = img.rotate(180)
这篇关于PIL - 图像不旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!