diff --git a/PIL/Image.py b/PIL/Image.py index 682fa6056..ed1d10907 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -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)) diff --git a/Tests/images/radial_gradient_L.png b/Tests/images/radial_gradient_L.png new file mode 100644 index 000000000..95309d7c0 Binary files /dev/null and b/Tests/images/radial_gradient_L.png differ diff --git a/Tests/images/radial_gradient_P.png b/Tests/images/radial_gradient_P.png new file mode 100644 index 000000000..1990749cc Binary files /dev/null and b/Tests/images/radial_gradient_P.png differ diff --git a/Tests/test_image.py b/Tests/test_image.py index d345ee5da..9034de720 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -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()