Skip to content

Commit

Permalink
Merge pull request #5562 from radarhere/expand
Browse files Browse the repository at this point in the history
Corrected border position for P mode in ImageOps.expand()
  • Loading branch information
mergify[bot] committed Jun 29, 2021
2 parents 28330c2 + 3e5ceb6 commit 49b6dc6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Tests/test_imageops.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageOps.py
Expand Up @@ -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))
Expand Down

0 comments on commit 49b6dc6

Please sign in to comment.