diff --git a/Tests/images/rotate_45_no_fill.png b/Tests/images/rotate_45_no_fill.png new file mode 100644 index 000000000..3c9d03e6c Binary files /dev/null and b/Tests/images/rotate_45_no_fill.png differ diff --git a/Tests/images/rotate_45_with_fill.png b/Tests/images/rotate_45_with_fill.png new file mode 100644 index 000000000..05b2d34d5 Binary files /dev/null and b/Tests/images/rotate_45_with_fill.png differ diff --git a/Tests/test_image_rotate.py b/Tests/test_image_rotate.py index fbcf9008d..61ce78a71 100644 --- a/Tests/test_image_rotate.py +++ b/Tests/test_image_rotate.py @@ -96,6 +96,18 @@ class TestImageRotate(PillowTestCase): self.rotate(im, im.mode, 45, center=(0, 0)) self.rotate(im, im.mode, 45, translate=(im.size[0]/2, 0)) self.rotate(im, im.mode, 45, center=(0, 0), translate=(im.size[0]/2, 0)) + + def test_rotate_no_fill(self): + im = Image.new('RGB', (100, 100), 'green') + target = Image.open('Tests/images/rotate_45_no_fill.png') + im = im.rotate(45) + self.assert_image_equal(im, target) + + def test_rotate_with_fill(self): + im = Image.new('RGB', (100, 100), 'green') + target = Image.open('Tests/images/rotate_45_with_fill.png') + im = im.rotate(45, fillcolor='white') + self.assert_image_equal(im, target) if __name__ == '__main__': diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 379a1d8a6..22ee46bfc 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1749,7 +1749,7 @@ class Image(object): return self._new(self.im.resize(size, resample, box)) def rotate(self, angle, resample=NEAREST, expand=0, center=None, - translate=None): + translate=None, fillcolor=None): """ Returns a rotated copy of this image. This method returns a copy of this image, rotated the given number of degrees counter @@ -1771,6 +1771,7 @@ class Image(object): :param center: Optional center of rotation (a 2-tuple). Origin is the upper left corner. Default is the center of the image. :param translate: An optional post-rotate translation (a 2-tuple). + :param fillcolor: An optional color for area outside the rotated image. :returns: An :py:class:`~PIL.Image.Image` object. """ @@ -1851,7 +1852,7 @@ class Image(object): matrix) w, h = nw, nh - return self.transform((w, h), AFFINE, matrix, resample) + return self.transform((w, h), AFFINE, matrix, resample, fillcolor=fillcolor) def save(self, fp, format=None, **params): """