mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-28 02:04:36 +03:00
Expose and test radial_gradient
This commit is contained in:
parent
3ead178d18
commit
07af06bf8c
|
@ -2576,3 +2576,12 @@ def linear_gradient(mode):
|
||||||
:param mode: Input mode.
|
:param mode: Input mode.
|
||||||
"""
|
"""
|
||||||
return Image()._new(core.linear_gradient(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))
|
||||||
|
|
BIN
Tests/images/radial_gradient_L.png
Normal file
BIN
Tests/images/radial_gradient_L.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
BIN
Tests/images/radial_gradient_P.png
Normal file
BIN
Tests/images/radial_gradient_P.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -342,6 +342,32 @@ class TestImage(PillowTestCase):
|
||||||
mode))
|
mode))
|
||||||
self.assert_image_equal(im, im2)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user