PIL - 图像不旋转
PIL - Images not rotating
我很好奇为什么我的图像没有旋转,它每次都处于相同的位置。
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'
无论我告诉图像旋转多少度,它最终都会在相同的位置。
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 度的图像结束。我做错了什么吗?
来自 (DOCS)
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()
返回的图像。可能是这样的:
if exif_data['Orientation'] == 6:
new_image = img.rotate(180)
我很好奇为什么我的图像没有旋转,它每次都处于相同的位置。
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'
无论我告诉图像旋转多少度,它最终都会在相同的位置。
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 度的图像结束。我做错了什么吗?
来自 (DOCS)
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()
返回的图像。可能是这样的:
if exif_data['Orientation'] == 6:
new_image = img.rotate(180)