Rotate and/or flip an image to respect the image's EXIF orientation data.
964659
def exif_orientation(im):
    
    try:
        exif = im._getexif()
    except Exception:
        # There are many ways that _getexif fails, we're just going to blanket
        # cover them all.
        exif = None
    if exif:
        orientation = exif.get(0x0112)
        if orientation == 2:
            im = im.transpose(Image.FLIP_LEFT_RIGHT)
        elif orientation == 3:
            im = im.transpose(Image.ROTATE_180)
        elif orientation == 4:
            im = im.transpose(Image.FLIP_TOP_BOTTOM)
        elif orientation == 5:
            im = im.transpose(Image.ROTATE_270).transpose(Image.FLIP_LEFT_RIGHT)
        elif orientation == 6:
            im = im.transpose(Image.ROTATE_270)
        elif orientation == 7:
            im = im.transpose(Image.ROTATE_90).transpose(Image.FLIP_LEFT_RIGHT)
        elif orientation == 8:
            im = im.transpose(Image.ROTATE_90)
    return im
88189
public function autoRotate()
	{
		if (!$this->checkPackageRequirements('exif'))
		{
			$this->setError(\Lang::txt('You need the PHP exif library installed to rotate image based on Exif Orientation value.'));
			return false;
		}

		if ($this->image_type == IMAGETYPE_JPEG)
		{
			try
			{
				$this->exif_data = exif_read_data($this->source);
			}
			catch (Exception $e)
			{
				$this->exif_data = array();
			}

			if (isset($this->exif_data['Orientation']))
			{
				switch ($this->exif_data['Orientation'])
				{
					case 2:
						$this->flip(true, false);
						break;

					case 3:
						$this->rotate(180);
						break;

					case 4:
						$this->flip(false, true);
						break;

					case 5:
						$this->rotate(270);
						$this->flip(true, false);
						break;

					case 6:
						$this->rotate(270);
						break;

					case 7:
						$this-rotate(90);
						$this->flip(true, false);
						break;

					case 8:
						$this->rotate(90);
						break;
				}
			}
		}
	}
1143799
def auto_orient(self):
        """"""
        image = self.get_image()
        if image is None:
            return
        invert_y = not isinstance(image, AstroImage.AstroImage)

        # Check for various things to set based on metadata
        header = image.get_header()
        if header:
            # Auto-orientation
            orient = header.get('Orientation', None)
            if orient is None:
                orient = header.get('Image Orientation', None)
            if orient is not None:
                self.logger.debug("orientation [%s]" % orient)
                try:
                    orient = int(str(orient))
                    self.logger.info(
                        "setting orientation from metadata [%d]" % (orient))
                    flip_x, flip_y, swap_xy = self.orient_map[orient]

                    self.transform(flip_x, flip_y, swap_xy)
                    invert_y = False

                except Exception as e:
                    # problems figuring out orientation--let it be
                    self.logger.error("orientation error: %s" % str(e))

        if invert_y:
            flip_x, flip_y, swap_xy = self.get_transforms()
            #flip_y = not flip_y
            flip_y = True
            self.transform(flip_x, flip_y, swap_xy)
605834
def get_exif_data(self, image):
        """"""
        exif_data = {}
        info = image._getexif()
        if info:
            for tag, value in info.items():
                decoded = TAGS.get(tag, tag)
                if decoded == "GPSInfo":
                    gps_data = {}
                    for t in value:
                        sub_decoded = GPSTAGS.get(t, t)
                        gps_data[sub_decoded] = value[t]

                    exif_data[decoded] = gps_data
                else:
                    exif_data[decoded] = value

        return exif_data
572304
def rotate(self, theta_deg, xoff=0, yoff=0):
        
        self.rotate_deg([theta_deg], (xoff, yoff))
939289
function rotatePixels(buffer, width, height, degrees) {
  let loops = degrees / 90
  while (loops > 0) {
    const newBuffer = Buffer.alloc(buffer.length)
    let newOffset = 0
    for (let x = 0; x < width; x += 1) {
      for (let y = height - 1; y >= 0; y -= 1) {
        const offset = (width * y + x) << 2
        const pixel = buffer.readUInt32BE(offset, true)
        newBuffer.writeUInt32BE(pixel, newOffset, true)
        newOffset += 4
      }
    }
    buffer = newBuffer
    const newHeight = width
    width = height
    height = newHeight
    loops -= 1
  }
  return buffer
}
88539
def flip(self, axis=0, preserve_centroid=False):
        '''
        

        '''
        self.v[:, axis] *= -1

        if preserve_centroid:
            self.v[:, axis] -= 2 * self.centroid[0]

        self.flip_faces()
869417
def rotateImage(image, angle):
    
    image = [list(row) for row in image]

    for n in range(angle % 4):
        image = list(zip(*image[::-1]))

    return image
1167333
def rotate_image_180():
    '''  '''

    # Create the media service
    mycam = ONVIFCamera('192.168.0.112', 80, 'admin', '12345')
    media_service = mycam.create_media_service()

    profiles = media_service.GetProfiles()

    # Use the first profile and Profiles have at least one
    token = profiles[0]._token

    # Get all video source configurations
    configurations_list = media_service.GetVideoSourceConfigurations()

    # Use the first profile and Profiles have at least one
    video_source_configuration = configurations_list[0]

    # Enable rotate
    video_source_configuration.Extension[0].Rotate[0].Mode[0] = 'OFF'

    # Create request type instance
    request = media_service.create_type('SetVideoSourceConfiguration')
    request.Configuration = video_source_configuration

    # ForcePersistence is obsolete and should always be assumed to be True
    request.ForcePersistence = True

    # Set the video source configuration
    media_service.SetVideoSourceConfiguration(request)
325424
private function autoRotate(string $path): self
    {
        $exifData = exif_read_data($path);
        if (false !== $exifData && true === array_key_exists('Orientation', $exifData)) {
            $imageData = null;
            switch ($exifData['Orientation']) {
                case self::ORIENTATION_UPSIDE_DOWN:
                    $imageData = imagerotate($this->workingData, 180, 0);
                    break;
                case self::ORIENTATION_ROTATE_COUNTER_CLOCKWISE:
                    $imageData = imagerotate($this->workingData, -90, 0);
                    break;
                case self::ORIENTATION_ROTATE_CLOCKWISE:
                    $imageData = imagerotate($this->workingData, 90, 0);
                    break;
            }
            if (null !== $imageData) {
                $this->workingData = $imageData;
            }
        }
        return $this;
    }
1320481
public static int getForceRotatedInvertedExifOrientation(
      RotationOptions rotationOptions, EncodedImage encodedImage) {
    int exifOrientation = encodedImage.getExifOrientation();
    int index = INVERTED_EXIF_ORIENTATIONS.indexOf(exifOrientation);
    if (index < 0) {
      throw new IllegalArgumentException("Only accepts inverted exif orientations");
    }
    int forcedAngle = RotationOptions.NO_ROTATION;
    if (!rotationOptions.useImageMetadata()) {
      forcedAngle = rotationOptions.getForcedAngle();
    }
    int timesToRotate = forcedAngle / 90;
    return INVERTED_EXIF_ORIENTATIONS.get(
        (index + timesToRotate) % INVERTED_EXIF_ORIENTATIONS.size());
  }
446783
def rotate_img_and_crop(img, angle):
    
    h, w, _ = img.shape
    img = scipy.ndimage.interpolation.rotate(img, angle)
    w, h = _rotatedRectWithMaxArea(w, h, math.radians(angle))
    return crop_center(img, int(h), int(w))
1373161
def add_orientation(self, orientation):
        """"""
        if not orientation in range(1, 9):
            print_error(
                "Error value for orientation, value must be in range(1,9), setting to default 1")
            self._ef['0th'][piexif.ImageIFD.Orientation] = 1
        else:
            self._ef['0th'][piexif.ImageIFD.Orientation] = orientation
1349146
public function flip($horizontal = true) {
		if (function_exists('imageflip')) {
			imageflip($this->_image, $horizontal ? IMG_FLIP_HORIZONTAL : IMG_FLIP_VERTICAL);
		} else {
			$image = imagecreatetruecolor($this->width, $this->height);
			imagealphablending($image, false);
			imagesavealpha($image, true);
			if ($horizontal) {
				$dst_y = 0;
				$src_y = 0;
				$coordinate = ($this->width - 1);
				foreach (range($this->width, 0) as $range) {
					$src_x = $range;
					$dst_x = $coordinate - $range;
					imagecopy($image, $this->_image, $dst_x, $dst_y, $src_x, $src_y, 1, $this->height);
				}
			} else {
				$dst_x = 0;
				$src_x = 0;
				$coordinate = ($this->height - 1);
				foreach (range($this->height, 0) as $range) {
					$src_y = $range;
					$dst_y = $coordinate - $range;
					imagecopy($image, $this->_image, $dst_x, $dst_y, $src_x, $src_y, $this->width, 1);
				}
			}
			imagedestroy($this->_image);
			$this->_image = $image;
		}
		return $this;
	}
281546
def flip(self):
        '''
        
        '''
        tmp = self.A.xyz
        self.A = self.B
        self.B = tmp
493525
public static void rotate(Image image, int degree, ImageOutputStream out) throws IORuntimeException {
		writeJpg(rotate(image, degree), out);
	}
498554
public function rotateExif()
    {
        if (!in_array($this->fileType, array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM))) {
            $this->log("Autorotate ignored, EXIF not supported by this filetype.");
            return $this;
        }

        $exif = exif_read_data($this->pathToImage);

        if (!empty($exif['Orientation'])) {
            switch ($exif['Orientation']) {
                case 3:
                    $this->log("Autorotate 180.");
                    $this->rotate(180, $this->bgColor);
                    break;

                case 6:
                    $this->log("Autorotate -90.");
                    $this->rotate(-90, $this->bgColor);
                    break;

                case 8:
                    $this->log("Autorotate 90.");
                    $this->rotate(90, $this->bgColor);
                    break;

                default:
                    $this->log("Autorotate ignored, unknown value as orientation.");
            }
        } else {
            $this->log("Autorotate ignored, no orientation in EXIF.");
        }

        return $this;
    }