From 3e5ceb6d679981b2e13e1cb8d1b5dfbd122b64b2 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 29 Jun 2021 21:24:41 +1000 Subject: [PATCH] Corrected border position --- Tests/test_imageops.py | 8 +++++++- src/PIL/ImageOps.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/test_imageops.py b/Tests/test_imageops.py index acd20bb58..dc20d432f 100644 --- a/Tests/test_imageops.py +++ b/Tests/test_imageops.py @@ -161,7 +161,13 @@ def test_expand_palette(): im_expanded = ImageOps.expand(im, 10, (255, 0, 0)) px = im_expanded.convert("RGB").load() - assert px[0, 0] == (255, 0, 0) + for b in range(10): + for x in range(im_expanded.width): + assert px[x, b] == (255, 0, 0) + assert px[x, im_expanded.height - 1 - b] == (255, 0, 0) + for y in range(im_expanded.height): + assert px[b, x] == (255, 0, 0) + assert px[b, im_expanded.width - 1 - b] == (255, 0, 0) im_cropped = im_expanded.crop( (10, 10, im_expanded.width - 10, im_expanded.height - 10) diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index 98be4bb91..711a519fc 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -399,7 +399,7 @@ def expand(image, border=0, fill=0): out.paste(image, (left, top)) draw = ImageDraw.Draw(out) - draw.rectangle((0, 0, width, height), outline=color, width=border) + draw.rectangle((0, 0, width - 1, height - 1), outline=color, width=border) else: out = Image.new(image.mode, (width, height), color) out.paste(image, (left, top))