Expose and test radial_gradient

This commit is contained in:
hugovk 2017-01-29 18:44:24 +02:00
parent 3ead178d18
commit 07af06bf8c
4 changed files with 35 additions and 0 deletions

View File

@ -2576,3 +2576,12 @@ def linear_gradient(mode):
:param mode: Input mode.
"""
return Image()._new(core.linear_gradient(mode))
def radial_gradient(mode):
"""
Generate 256x256 radial gradient from black to white, centre to edge.
:param mode: Input mode.
"""
return Image()._new(core.radial_gradient(mode))

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -342,6 +342,32 @@ class TestImage(PillowTestCase):
mode))
self.assert_image_equal(im, im2)
def test_radial_gradient_wrong_mode(self):
# Arrange
wrong_mode = "RGB"
# Act / Assert
self.assertRaises(ValueError,
lambda: Image.radial_gradient(wrong_mode))
return
def test_radial_gradient(self):
# Arrange
for mode in ["L", "P"]:
# Act
im = Image.radial_gradient(mode)
# Assert
self.assertEqual(im.size, (256, 256))
self.assertEqual(im.mode, mode)
self.assertEqual(im.getpixel((0, 0)), 255)
self.assertEqual(im.getpixel((128, 128)), 0)
im2 = Image.open('Tests/images/radial_gradient_{}.png'.format(
mode))
self.assert_image_equal(im, im2)
if __name__ == '__main__':
unittest.main()