Skip to content

Commit f9d3ee0

Browse files
committed
Round position in pad()
1 parent df4bb34 commit f9d3ee0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Tests/test_imageops.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ def test_pad():
140140
)
141141

142142

143+
def test_pad_round():
144+
im = Image.new("1", (1, 1), 1)
145+
new_im = ImageOps.pad(im, (4, 1))
146+
assert new_im.load()[2, 0] == 1
147+
148+
new_im = ImageOps.pad(im, (1, 4))
149+
assert new_im.load()[0, 2] == 1
150+
151+
143152
def test_pil163():
144153
# Division by zero in equalize if < 255 pixels in image (@PIL163)
145154

src/PIL/ImageOps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ def pad(image, size, method=Image.Resampling.BICUBIC, color=None, centering=(0.5
292292
else:
293293
out = Image.new(image.mode, size, color)
294294
if resized.width != size[0]:
295-
x = int((size[0] - resized.width) * max(0, min(centering[0], 1)))
295+
x = round((size[0] - resized.width) * max(0, min(centering[0], 1)))
296296
out.paste(resized, (x, 0))
297297
else:
298-
y = int((size[1] - resized.height) * max(0, min(centering[1], 1)))
298+
y = round((size[1] - resized.height) * max(0, min(centering[1], 1)))
299299
out.paste(resized, (0, y))
300300
return out
301301

0 commit comments

Comments
 (0)