Skip to content

Commit 9f7010d

Browse files
radarherelukegb
authored andcommitted
Copy image if expanding by zero
1 parent dfe04d5 commit 9f7010d

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

Tests/test_image_filter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def test_invalid_box_blur_filter(radius: int | tuple[int, int]) -> None:
232232

233233
def test_rankfilter_size_1() -> None:
234234
im = Image.new("L", (3, 3), 128)
235+
235236
# Size 1 should not crash (margin is 0)
236237
assert im.filter(ImageFilter.MinFilter(1)).getpixel((1, 1)) == 128
237238
assert im.filter(ImageFilter.MaxFilter(1)).getpixel((1, 1)) == 128

src/_imaging.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,9 @@ _expand_image(ImagingObject *self, PyObject *args) {
11151115
return NULL;
11161116
}
11171117

1118+
if (m == 0) {
1119+
return PyImagingNew(ImagingCopy(self->image));
1120+
}
11181121
return PyImagingNew(ImagingExpand(self->image, m));
11191122
}
11201123

0 commit comments

Comments
 (0)