Merge pull request #3057 from storesource/RotateImagewithColor

Enabling background colour parameter on rotate
This commit is contained in:
Hugo 2018-04-05 09:45:22 +01:00 committed by GitHub
commit 0567a54cd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

View File

@ -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__':

View File

@ -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):
"""