'Rotates the image in the buffer so that it is oriented correctly.
If override_exif is True (default) then the metadata
orientation is adjusted as well.
:param override_exif: If the metadata should be adjusted as well.
:type override_exif: Boolean'

def reorientate(self, override_exif=True):

    orientation = self.get_orientation()
    if (orientation is None):
        return
    if (orientation == 2):
        self.flip_horizontally()
    elif (orientation == 3):
        self.rotate(180)
    elif (orientation == 4):
        self.flip_vertically()
    elif (orientation == 5):
        self.flip_vertically()
        self.rotate(270)
    elif (orientation == 6):
        self.rotate(270)
    elif (orientation == 7):
        self.flip_horizontally()
        self.rotate(270)
    elif (orientation == 8):
        self.rotate(90)
    if ((orientation != 1) and override_exif):
        segment = self._get_exif_segment()
        if (segment and segment.get_primary()):
            segment.primary['Orientation'] = [1]
            self.exif = segment.get_data()
