code: def apply_exif_orientation(image):
      try:
          exif = image._getexif()
      except AttributeError:
          exif = None
  
      if exif is None:
          return image
  
      exif = {
          PIL.ExifTags.TAGS[k]: v
          for k, v in exif.items()
          if k in PIL.ExifTags.TAGS
      }
  
      orientation = exif.get("Orientation", None)
  
      if orientation == 1:
          # do nothing
          return image
      elif orientation == 2:
          # left-to-right mirror
          return PIL.ImageOps.mirror(image)
      elif orientation == 3:
          # rotate 180
          return image.transpose(PIL.Image.ROTATE_180)
      elif orientation == 4:
          # top-to-bottom mirror
          return PIL.ImageOps.flip(image)
      elif orientation == 5:
          # top-to-left mirror
          return PIL.ImageOps.mirror(
              image.transpose(PIL.Image.ROTATE_270)
          )
      elif orientation == 6:
          # rotate 270
          return image.transpose(PIL.Image.ROTATE_270)
      elif orientation == 7:
          # top-to-right mirror
          return PIL.ImageOps.mirror(
              image.transpose(PIL.Image.ROTATE_90)
          )
      elif orientation == 8:
          # rotate 90
          return image.transpose(PIL.Image.ROTATE_90)
      else:
          return image
  
imports: import argparse
  import collections
  import datetime
  import glob
  import json
  import os
  import os.path
  import sys
  import uuid
  import PIL
  import io
  import base64
  import logging
  import math
  import imgviz
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: apply_exif_orientation(image) and returns: image, image, PIL, image, PIL, PIL, image, PIL, image, image