mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Expose and test linear_gradient
This commit is contained in:
parent
6d11fa23dd
commit
47b1c66961
|
@ -2558,3 +2558,12 @@ def effect_noise(size, sigma):
|
|||
:param sigma: Standard deviation of noise.
|
||||
"""
|
||||
return Image()._new(core.effect_noise(size, sigma))
|
||||
|
||||
|
||||
def linear_gradient(mode):
|
||||
"""
|
||||
Generate 256x256 linear gradient from black to white, top to bottom.
|
||||
|
||||
:param mode: Input mode.
|
||||
"""
|
||||
return Image()._new(core.linear_gradient(mode))
|
||||
|
|
BIN
Tests/images/linear_gradient_L.png
Normal file
BIN
Tests/images/linear_gradient_L.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 516 B |
BIN
Tests/images/linear_gradient_P.png
Normal file
BIN
Tests/images/linear_gradient_P.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -315,6 +315,32 @@ class TestImage(PillowTestCase):
|
|||
def test_fromstring(self):
|
||||
self.assertRaises(NotImplementedError, Image.fromstring)
|
||||
|
||||
def test_linear_gradient_wrong_mode(self):
|
||||
# Arrange
|
||||
wrong_mode = "RGB"
|
||||
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError,
|
||||
lambda: Image.linear_gradient(wrong_mode))
|
||||
return
|
||||
|
||||
def test_linear_gradient(self):
|
||||
|
||||
# Arrange
|
||||
for mode in ["L", "P"]:
|
||||
|
||||
# Act
|
||||
im = Image.linear_gradient(mode)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(im.size, (256, 256))
|
||||
self.assertEqual(im.mode, mode)
|
||||
self.assertEqual(im.getpixel((0, 0)), 0)
|
||||
self.assertEqual(im.getpixel((255, 255)), 255)
|
||||
im2 = Image.open('Tests/images/linear_gradient_{}.png'.format(
|
||||
mode))
|
||||
self.assert_image_equal(im, im2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user