mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-25 00:34:14 +03:00
Merge pull request #3057 from storesource/RotateImagewithColor
Enabling background colour parameter on rotate
This commit is contained in:
commit
0567a54cd7
BIN
Tests/images/rotate_45_no_fill.png
Normal file
BIN
Tests/images/rotate_45_no_fill.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 639 B |
BIN
Tests/images/rotate_45_with_fill.png
Normal file
BIN
Tests/images/rotate_45_with_fill.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 625 B |
|
@ -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__':
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user