def test_rotate(self): a = AffineTransform() self.assertEqual(a.rotate(0), a) self.assertEqual(a.rotate(360), a) self.assertEqual(a.rotate(90), a.rotate(270, clockwise=True)) self.assertEqual(a.rotate(90), AffineTransform((0, -1, 0, 1, 0, 0, 0, 0, 1)))
def test_rotate(self): a = AffineTransform() self.assertEqual(a.rotate(0), a) self.assertEqual(a.rotate(360), a) self.assertEqual(a.rotate(90), a.rotate(270, clockwise=True)) self.assertEqual(a.rotate(90), AffineTransform((0, -1, 0, 1, 0, 0, 0, 0, 1)))
def rotate(self, degrees, clockwise=False, resample_algorithm=nearest, resize_canvas=True): """ Returns the image obtained by rotating this image by the given number of degrees. Anticlockwise unless clockwise=True is given. """ # translate to the origin first, then rotate, then translate back transform = AffineTransform() transform = transform.translate(self.width * -0.5, self.height * -0.5) transform = transform.rotate(degrees, clockwise=clockwise) width, height = self.width, self.height if resize_canvas: # determine new width width, height = get_transformed_dimensions(transform, (0, 0, width, height)) transform = transform.translate(width * 0.5, height * 0.5) pixels = resample_algorithm.affine(self, transform, resize_canvas=resize_canvas) return self._copy(pixels)
def rotate(self, degrees, clockwise=False, resample_algorithm=nearest, resize_canvas=True): """ Returns the image obtained by rotating this image by the given number of degrees. Anticlockwise unless clockwise=True is given. """ # translate to the origin first, then rotate, then translate back transform = AffineTransform() transform = transform.translate(self.width * -0.5, self.height * -0.5) transform = transform.rotate(degrees, clockwise=clockwise) width, height = self.width, self.height if resize_canvas: # determine new width width, height = get_transformed_dimensions(transform, (0, 0, width, height)) transform = transform.translate(width * 0.5, height * 0.5) pixels = resample_algorithm.affine(self, transform, resize_canvas=resize_canvas) return self._copy(pixels)