Merge pull request #3326 from radarhere/edge

Catch ValueError when processing the edge of an image in ImageDraw.floodfill
This commit is contained in:
Hugo 2018-09-01 11:27:10 +03:00 committed by GitHub
commit 97e9dbaefd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -366,6 +366,11 @@ class TestImageDraw(PillowTestCase):
ImageDraw.floodfill(im, (W, H), red)
self.assert_image_equal(im, im_floodfill)
# Test filling at the edge of an image
im = Image.new("RGB", (1, 1))
ImageDraw.floodfill(im, (0, 0), red)
self.assert_image_equal(im, Image.new("RGB", (1, 1), red))
def test_floodfill_border(self):
# floodfill() is experimental

View File

@ -358,7 +358,7 @@ def floodfill(image, xy, value, border=None, thresh=0):
for (s, t) in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)):
try:
p = pixel[s, t]
except IndexError:
except (ValueError, IndexError):
pass
else:
if _color_diff(p, background) <= thresh:
@ -372,7 +372,7 @@ def floodfill(image, xy, value, border=None, thresh=0):
for (s, t) in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)):
try:
p = pixel[s, t]
except IndexError:
except (ValueError, IndexError):
pass
else:
if p != value and p != border: