I would imagine that the images you are dealing with have an EXIF orientation tag. This means that the image data is saved in one position, and then the image instructs the viewer to rotate it another way.
먼저, EXIF는 Exchangeable image file format의 약자로 digital camera로 찍힌 이미지에 대한 다양한 meta 정보를 저장하는 프로토콜이다. EXIF 는 실제 이미지와 함께 저장되는데 shutter speed, focal length, orientation, shooting time 정보들이 있다.
그중 내가 관심있는 orientation tag는 1~8까지의 값을 가진다.
이미지에서 orientation tag를 얻는 방법
from PIL.ExifTags import TAGS
from PIL import Image
image_path = 'service_coke.jpeg'
img = Image.open(image_path)
exif = img.getexif()
for k, v in exif.items():
print('{}: {}'.format(TAGS[k], v))
def exif_transpose(image, *, in_place=False):
"""
If an image has an EXIF Orientation tag, other than 1, transpose the image
accordingly, and remove the orientation data.
:param image: The image to transpose.
:param in_place: Boolean. Keyword-only argument.
If ``True``, the original image is modified in-place, and ``None`` is returned.
If ``False`` (default), a new :py:class:`~PIL.Image.Image` object is returned
with the transposition applied. If there is no transposition, a copy of the
image will be returned.
"""
- exif_transpose 함수는 이미지에 EXIF Orientation tag 정보가 있으면 이를 이용하여 image를 보여준다.