In-place 90 degree image rotation in the counter-clockwise direction.  Only works on
square images.
546743
public static void rotateCCW( GrayS64 image ) {
		if( image.width != image.height )
			throw new IllegalArgumentException("Image must be square");

		int w = image.height/2 + image.height%2;
		int h = image.height/2;

		for( int y0 = 0; y0 < h; y0++ ) {
			int y1 = image.height-y0-1;

			for( int x0 = 0; x0 < w; x0++ ) {
				int x1 = image.width-x0-1;

				int index0 = image.startIndex + y0*image.stride + x0;
				int index1 = image.startIndex + x0*image.stride + y1;
				int index2 = image.startIndex + y1*image.stride + x1;
				int index3 = image.startIndex + x1*image.stride + y0;
				
				long tmp0 = image.data[index0];

				image.data[index0] = image.data[index1];
				image.data[index1] = image.data[index2];
				image.data[index2] = image.data[index3];
				image.data[index3] = (long)tmp0;
			}
		}
	}
695600
def rotate_img(im, deg, mode=cv2.BORDER_CONSTANT, interpolation=cv2.INTER_AREA):
    
    r,c,*_ = im.shape
    M = cv2.getRotationMatrix2D((c//2,r//2),deg,1)
    return cv2.warpAffine(im,M,(c,r), borderMode=mode, flags=cv2.WARP_FILL_OUTLIERS+interpolation)
749925
def do_rotation(self, mirror, rot):
        """"""
        infile = self.tmpfile
        outfile = self.basename + '.rot'
        # NOTE: pnmrotate: angle must be between -90 and 90 and
        # rotations is CCW not CW per IIIF spec
        #
        # BUG in pnmrotate: +90 and -90 rotations the output image
        # size may be off. See for example a 1000x1000 image becoming
        # 1004x1000:
        #
        # simeon@RottenApple iiif>file testimages/67352ccc-d1b0-11e1-89ae-279075081939.png
        # testimages/67352ccc-d1b0-11e1-89ae-279075081939.png: PNG image data, 1000 x 1000, 8-bit/color RGB, non-interlaced
        # simeon@RottenApple iiif>cat testimages/67352ccc-d1b0-11e1-89ae-279075081939.png  | pngtopnm | pnmrotate -90 | pnmtopng > a.png; file a.png; rm a.png
        # a.png: PNG image data, 1004 x 1000, 8-bit/color RGB, non-interlaced
        # simeon@RottenApple iiif>cat testimages/67352ccc-d1b0-11e1-89ae-279075081939.png  | pngtopnm | pnmrotate 90 | pnmtopng > a.png; file a.png; rm a.png
        # a.png: PNG image data, 1004 x 1000, 8-bit/color RGB, non-interlaced
        #
        # WORKAROUND is to add a pnmscale for the 90degree case, some
        # simeon@RottenApple iiif>cat testimages/67352ccc-d1b0-11e1-89ae-279075081939.png  | pngtopnm | pnmrotate -90| pnmscale -width 1000 -height 1000 | pnmtopng > a.png; file a.png; rm a.png
        # a.png: PNG image data, 1000 x 1000, 8-bit/color RGB, non-interlaced
        #
        # FIXME - add mirroring
        #
        if (rot == 0.0):
            # print "rotation: no rotation"
            self.tmpfile = infile
        elif (rot <= 90.0 or rot >= 270.0):
            if (rot >= 270.0):
                rot -= 360.0
            # print "rotation: by %f degrees clockwise" % (rot)
            if (self.shell_call('cat ' + infile + ' | ' + self.pnmrotate + ' -background=#FFF ' + str(-rot) + '  > ' + outfile)):
                raise IIIFError(
                    text="Oops... got nonzero output from pnmrotate.")
            self.tmpfile = outfile
        else:
            # Between 90 and 270 = flip and then -90 to 90
            rot -= 180.0
            # print "rotation: by %f degrees clockwise" % (rot)
            if (self.shell_call('cat ' + infile + ' | ' + self.pnmflip + ' -rotate180 | ' + self.pnmrotate + ' ' + str(-rot) + '  > ' + outfile)):
                raise IIIFError(
                    text="Oops... got nonzero output from pnmrotate.")
            self.tmpfile = outfile
        # Fixup size for 90s
        if (abs(rot % 180.0 - 90.0) < 0.001):
            outfile2 = self.basename + '.rot2'
            if (self.shell_call('cat ' + self.tmpfile + ' | ' + self.pnmscale + ' -width ' + str(self.height) + ' -height ' + str(self.width) + ' > ' + outfile2)):
                raise IIIFError(
                    text="Oops... failed to fixup size after pnmrotate.")
            self.tmpfile = outfile2
125688
public static Bitmap rotate(Bitmap bmp, float angle) {
        Matrix matrixRotateLeft = new Matrix();
        matrixRotateLeft.setRotate(angle);
        return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrixRotateLeft, true);
    }
1210358
def to_polar(image):
    
    # xy image, origin in the centre, scaled to fit image to a circle
    xy = pyvips.Image.xyz(image.width, image.height)
    xy -= [image.width / 2.0, image.height / 2.0]
    scale = min(image.width, image.height) / float(image.width)
    xy *= 2.0 / scale

    index = xy.polar()

    # scale vertical axis to 360 degrees
    index *= [1, image.height / 360.0]

    return image.mapim(index)
245550
def draw_tile_rot(x = 0, y = 0, angle = 90, opts = {})
      opts[:canvas] ||= @canvas
      opts[:sx] ||= 0
      opts[:sy] ||= 0
      opts[:swidth] ||= width - opts[:sx]
      opts[:sheight] ||= height - opts[:sy]
      opts[:dwidth] ||= opts[:swidth]
      opts[:dheight] ||= opts[:sheight]
      %x{
        var context = #{opts[:canvas].context};
        context.translate(#{x}, #{y});
        context.rotate(-#{angle-90}*Math.PI/180.0);
        context.drawImage(
          #{@img},
          #{opts[:sx]},
          #{opts[:sy]},
          #{opts[:swidth]},
          #{opts[:sheight]},
          -#{opts[:swidth]}/2,
          -#{opts[:sheight]}/2,
          #{opts[:swidth]},
          #{opts[:sheight]});
        context.rotate(#{angle-90}*Math.PI/180.0);
        context.translate(-#{x}, -#{y});
      }
    end
1229119
private function fixImageOrientation($image)
    {
        $orientation = $image->getImageOrientation();
        switch ($orientation) {
            case \Imagick::ORIENTATION_UNDEFINED:
                break;
            case \Imagick::ORIENTATION_TOPLEFT:
                break;
            case \Imagick::ORIENTATION_TOPRIGHT:
                $image->flopImage();
                $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
                break;
            case \Imagick::ORIENTATION_BOTTOMRIGHT:
                $image->rotateImage(new \ImagickPixel(), 180);
                $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
                break;
            case \Imagick::ORIENTATION_BOTTOMLEFT:
                $image->rotateImage(new \ImagickPixel(), 180);
                $image->flopImage();
                $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
                break;
            case \Imagick::ORIENTATION_LEFTTOP:
                $image->rotateImage(new \ImagickPixel(), 90);
                $image->flopImage();
                $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
                break;
            case \Imagick::ORIENTATION_RIGHTTOP:
                $image->rotateImage(new \ImagickPixel(), 90);
                $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
                break;
            case \Imagick::ORIENTATION_RIGHTBOTTOM:
                $image->rotateImage(new \ImagickPixel(), 270);
                $image->flopImage();
                $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
                break;
            case \Imagick::ORIENTATION_LEFTBOTTOM:
                $image->rotateImage(new \ImagickPixel(), 270);
                $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
                break;
        }

        return $image;
    }
891410
public void rotate(String photoId, int degrees) throws FlickrException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("method", METHOD_ROTATE);

        parameters.put("photo_id", photoId);
        parameters.put("degrees", String.valueOf(degrees));

        Response response = transportAPI.post(transportAPI.getPath(), parameters, apiKey, sharedSecret);
        if (response.isError()) {
            throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
        }
    }
1121339
def _rotate(degrees:uniform):
    ""
    angle = degrees * math.pi / 180
    return [[cos(angle), -sin(angle), 0.],
            [sin(angle),  cos(angle), 0.],
            [0.        ,  0.        , 1.]]
974539
function rotateImage(contentType, imgBuf, callback) {
    try {
        new Jimp(imgBuf, function (err, image) {
            if (err) {
                console.log('Image loading error: ' + err);
                callback(imgBuf);
            } else {
                image.rotate(180)
                .getBuffer(contentType, function (err, rotated) {
                    if (err) {
                        console.log('Image processing error: ' + err);
                        callback(imgBuf);
                    } else {
                        callback(rotated);
                    }
                });
            }
        });
    } catch (err) {
        /*
          Sometimes Jimp throws instead of passing error via the callback as it should.
          Sigh. e.g: "Image loading error: Error: Unsupported interlace method"
         */
        console.log('Jimp threw an error: ' + err);
        callback(imgBuf);
    }
}
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)
720290
def enforce_vertical_symmetry(pixmap):
    ''''''
    mirror = []
    for item in pixmap:
        y = item[0]
        x = item[1]

        if x <= IMAGE_APEX:
            diff_x = diff(x, IMAGE_APEX)
            mirror.append((y, x + (2 * diff_x) - 1))

        if x > IMAGE_APEX:
            diff_x = diff(x, IMAGE_APEX)
            mirror.append((y, x - (2 * diff_x) - 1))

    return mirror + pixmap
1270988
public static BufferedImage rotateImage(BufferedImage image, double angle) {
        double theta = Math.toRadians(angle);
        double sin = Math.abs(Math.sin(theta));
        double cos = Math.abs(Math.cos(theta));
        int w = image.getWidth();
        int h = image.getHeight();
        int newW = (int) Math.floor(w * cos + h * sin);
        int newH = (int) Math.floor(h * cos + w * sin);

        BufferedImage tmp = new BufferedImage(newW, newH, image.getType());
        Graphics2D g2d = tmp.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.translate((newW - w) / 2, (newH - h) / 2);
        g2d.rotate(theta, w / 2, h / 2);
        g2d.drawImage(image, 0, 0, null);
        g2d.dispose();
        return tmp;
    }
207247
def _rotate(pair, step):
        
        step = Step(step)
        movement = {
            "U": "RFLB", 
            "D": "LFRB", 
            "R": "FUBD", 
            "L": "FDBU", 
            "F": "URDL", 
            "B": "ULDR", 
            }[step.face]
        movement = {
            movement[i]: movement[(i + step.is_clockwise + (-1 * step.is_counter_clockwise) + (2 * step.is_180)) % 4]
            for i in range(4)
            }
        for cubie in pair:
            if step.face not in cubie:
                if cubie.type == "edge":
                    result_edge = cubie.copy()
                else:
                    result_corner = cubie.copy()
            else:
                result = {}
                for face, square in cubie:
                    if face not in movement:
                        result[face] = square
                    else:
                        result[movement[face]] = square
                if len(result) == 2:
                    result_edge = Edge(**result)
                else:
                    result_corner = Corner(**result)
        return (result_corner, result_edge)
930297
public function rotate($value = 90, $bgColor = 'transparent')
		# Author:     Jarrod Oberto
		# Date:       07-05-2011
		# Purpose:    Rotate image
		# Param in:   (mixed) $degrees: (int) number of degress to rotate image
		#               (str) param "left": rotate left
		#               (str) param "right": rotate right
		#               (str) param "upside": upside-down image
		# Param out:
		# Reference:
		# Notes:    The default direction of imageRotate() is counter clockwise.
		#
	{
		if ($this->imageResized)
		{

			if (is_integer($value))
			{
				$degrees = $value;
			}

			// *** Convert color
			$rgbArray = $this->formatColor($bgColor);
			$r = $rgbArray['r'];
			$g = $rgbArray['g'];
			$b = $rgbArray['b'];
			if (isset($rgbArray['a']))
			{
				$a = $rgbArray['a'];
			}

			if (is_string($value))
			{

				$value = fix_strtolower($value);

				switch ($value)
				{
					case 'left':
						$degrees = 90;
						break;
					case 'right':
						$degrees = 270;
						break;
					case 'upside':
						$degrees = 180;
						break;
					default:
						break;
				}

			}

			// *** The default direction of imageRotate() is counter clockwise
			//   * This makes it clockwise
			$degrees = 360 - $degrees;

			// *** Create background color
			$bg = ImageColorAllocateAlpha($this->imageResized, $r, $g, $b, $a);

			// *** Fill with background
			ImageFill($this->imageResized, 0, 0, $bg);

			// *** Rotate
			$this->imageResized = imagerotate($this->imageResized, $degrees, $bg); // Rotate 45 degrees and allocated the transparent colour as the one to make transparent (obviously)

			// Ensure alpha transparency
			ImageSaveAlpha($this->imageResized, true);

		}
	}
30613
def _validate_image_orientation(image_orientation):
    '''
    
    '''
    row_cosine, column_cosine, slice_cosine = _extract_cosines(image_orientation)

    if not _almost_zero(np.dot(row_cosine, column_cosine), 1e-4):
        raise DicomImportException("Non-orthogonal direction cosines: {}, {}".format(row_cosine, column_cosine))
    elif not _almost_zero(np.dot(row_cosine, column_cosine), 1e-8):
        logger.warning("Direction cosines aren't quite orthogonal: {}, {}".format(row_cosine, column_cosine))

    if not _almost_one(np.linalg.norm(row_cosine), 1e-4):
        raise DicomImportException("The row direction cosine's magnitude is not 1: {}".format(row_cosine))
    elif not _almost_one(np.linalg.norm(row_cosine), 1e-8):
        logger.warning("The row direction cosine's magnitude is not quite 1: {}".format(row_cosine))

    if not _almost_one(np.linalg.norm(column_cosine), 1e-4):
        raise DicomImportException("The column direction cosine's magnitude is not 1: {}".format(column_cosine))
    elif not _almost_one(np.linalg.norm(column_cosine), 1e-8):
        logger.warning("The column direction cosine's magnitude is not quite 1: {}".format(column_cosine))
314756
public function rotate($degrees = 90)
    {
        do {
            $img = imagerotate($this->im, -$degrees, imagecolorallocatealpha($this->im, 0, 0, 0, 127));
            imagedestroy($this->im);
            $this->im = $img;
        } while (!empty($this->gif) && $this->gifNext());

        $this->info['width']  = imagesx($this->im);
        $this->info['height'] = imagesy($this->im);

        return $this;
    }