当前位置: 代码迷 >> 综合 >> python-解决PIL读取图片出现旋转问题
  详细解决方案

python-解决PIL读取图片出现旋转问题

热度:27   发布时间:2023-10-19 18:23:05.0

我们很多时候在读取图片时候,发现读取进来的图片尺寸自动进行了旋转,这是由于拍摄的角度不同造成的,在处理坐标问题时,旋转后的图片就会造成很大的麻烦,如何将图片正常显示呢。一下方法:

import numpy as np
import os
from PIL import Image# image = Image.open('1.jpg')
# print(image.size)from PIL import Image, ExifTagsimg_file = './1.jpg'
image = Image.open(img_file)for orientation in ExifTags.TAGS.keys():if ExifTags.TAGS[orientation] == 'Orientation':break
exif = dict(image._getexif().items())if exif[orientation] == 3:image = image.rotate(180, expand=True)
elif exif[orientation] == 6:image = image.rotate(270, expand=True)
elif exif[orientation] == 8:image = image.rotate(90, expand=True)print(image.size)

  相关解决方案