Merge pull request #5562 from radarhere/expand

Corrected border position for P mode in ImageOps.expand()
This commit is contained in:
mergify[bot] 2021-06-29 12:07:09 +00:00 committed by GitHub
commit 49b6dc6866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -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)

View File

@ -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))