Beispiel #1
0
    def get_orientation(self, override_exif=True):
        if (not hasattr(self, 'exif')) or self.exif is None:
            return

        orientation = None

        try:
            segment = ExifSegment(None, None, self.exif, 'ro')
            primary = segment.primary
            orientation = primary['Orientation']
            if orientation:
                orientation = orientation[0]
                if orientation != 1 and override_exif:
                    primary['Orientation'] = [1]
                    self.exif = segment.get_data()
        except Exception:
            logger.exception('Ignored error handling exif for reorientation')
        finally:
            return orientation
Beispiel #2
0
    def reorientate(self):
        if (not hasattr(self, 'exif')) or self.exif is None:
            return

        orientation = None

        try:
            segment = ExifSegment(None, None, self.exif, 'ro')
            primary = segment.primary
            orientation = primary['Orientation']
            if orientation:
                orientation = orientation[0]
                if orientation != 1:
                    primary['Orientation'] = [1]
                    self.exif = segment.get_data()
        except Exception:
            logger.exception('Ignored error handling exif for reorientation')

        if orientation == 2:
            self.flip_horizontally()
        elif orientation == 3:
            self.rotate(180)
        elif orientation == 4:
            self.flip_vertically()
        elif orientation == 5:
            # Horizontal Mirror + Rotation 270
            self.flip_vertically()
            self.rotate(270)
        elif orientation == 6:
            self.rotate(270)
        elif orientation == 7:
            # Vertical Mirror + Rotation 270
            self.flip_horizontally()
            self.rotate(270)
        elif orientation == 8:
            self.rotate(90)
Beispiel #3
0
    def reorientate(self):
        if (not hasattr(self, 'exif')) or self.exif is None:
            return

        orientation = None

        try:
            segment = ExifSegment(None, None, self.exif, 'ro')
            primary = segment.primary
            orientation = primary['Orientation']
            if orientation:
                orientation = orientation[0]
                if orientation != 1:
                    primary['Orientation'] = [1]
                    self.exif = segment.get_data()
        except Exception:
            logger.exception('Ignored error handling exif for reorientation')

        if orientation == 2:
            self.flip_horizontally()
        elif orientation == 3:
            self.rotate(180)
        elif orientation == 4:
            self.flip_vertically()
        elif orientation == 5:
            # Horizontal Mirror + Rotation 270
            self.flip_vertically()
            self.rotate(270)
        elif orientation == 6:
            self.rotate(270)
        elif orientation == 7:
            # Vertical Mirror + Rotation 270
            self.flip_horizontally()
            self.rotate(270)
        elif orientation == 8:
            self.rotate(90)