def _apply_exif_orientation(image):
 try:
  exif_tags = (image._getexif() or {})
 except AttributeError:
  return image
 ORIENTATION_TAG_ID = 274
 orientation = exif_tags.get(ORIENTATION_TAG_ID)
 if (orientation == 1):
  pass
 elif (orientation == 2):
  image = image.transpose(Image.FLIP_LEFT_RIGHT)
 elif (orientation == 3):
  image = image.transpose(Image.ROTATE_180)
 elif (orientation == 4):
  image = image.transpose(Image.FLIP_TOP_BOTTOM)
 elif (orientation == 5):
  image = image.transpose(Image.FLIP_LEFT_RIGHT)
  image = image.transpose(Image.ROTATE_90)
 elif (orientation == 6):
  image = image.transpose(Image.ROTATE_270)
 elif (orientation == 7):
  image = image.transpose(Image.FLIP_LEFT_RIGHT)
  image = image.transpose(Image.ROTATE_270)
 elif (orientation == 8):
  image = image.transpose(Image.ROTATE_90)
 return image

def _apply_exif_orientation ( image ) : try : exif_tags = ( image . _getexif ( ) or { } ) except AttributeError : return image ORIENTATION_TAG_ID = 274 orientation = exif_tags . get ( ORIENTATION_TAG_ID ) if ( orientation == 1 ) : pass elif ( orientation == 2 ) : image = image . transpose ( Image . FLIP_LEFT_RIGHT ) elif ( orientation == 3 ) : image = image . transpose ( Image . ROTATE_180 ) elif ( orientation == 4 ) : image = image . transpose ( Image . FLIP_TOP_BOTTOM ) elif ( orientation == 5 ) : image = image . transpose ( Image . FLIP_LEFT_RIGHT ) image = image . transpose ( Image . ROTATE_90 ) elif ( orientation == 6 ) : image = image . transpose ( Image . ROTATE_270 ) elif ( orientation == 7 ) : image = image . transpose ( Image . FLIP_LEFT_RIGHT ) image = image . transpose ( Image . ROTATE_270 ) elif ( orientation == 8 ) : image = image . transpose ( Image . ROTATE_90 ) return image
update the images orientation if it has the relevant exif tag .