<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rotate(self, img):
 """ Rotate image if exif says it needs it """

        try:
            exif = image2exif.get_exif(img)
        except AttributeError:
            # image format doesn't support exif
            return img
        
        orientation = exif.get('Orientation', 1)

        landscape = img.height < img.width
        
        if orientation == 6 and landscape:
            print("ROTATING")
            return img.rotate(-90)

        return img