Skip to content

Commit 6cef133

Browse files
authored
Merge pull request #8201 from radarhere/resize
2 parents 4aa24f8 + 6990fc4 commit 6cef133

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

Tests/test_image_resize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,14 @@ def test_box_filter(
285285

286286
class TestImageResize:
287287
def test_resize(self) -> None:
288-
def resize(mode: str, size: tuple[int, int]) -> None:
288+
def resize(mode: str, size: tuple[int, int] | list[int]) -> None:
289289
out = hopper(mode).resize(size)
290290
assert out.mode == mode
291-
assert out.size == size
291+
assert out.size == tuple(size)
292292

293293
for mode in "1", "P", "L", "RGB", "I", "F":
294294
resize(mode, (112, 103))
295-
resize(mode, (188, 214))
295+
resize(mode, [188, 214])
296296

297297
# Test unknown resampling filter
298298
with hopper() as im:

Tests/test_numpy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ def test_putdata() -> None:
198198
assert len(im.getdata()) == len(arr)
199199

200200

201+
def test_resize() -> None:
202+
im = hopper()
203+
size = (64, 64)
204+
205+
im_resized = im.resize(numpy.array(size))
206+
207+
assert im_resized.size == size
208+
209+
201210
@pytest.mark.parametrize(
202211
"dtype",
203212
(

src/PIL/Image.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
)
6464
from ._binary import i32le, o32be, o32le
6565
from ._deprecate import deprecate
66-
from ._typing import StrOrBytesPath, TypeGuard
6766
from ._util import DeferredError, is_path
6867

6968
ElementTree: ModuleType | None
@@ -220,6 +219,7 @@ class Quantize(IntEnum):
220219

221220
if TYPE_CHECKING:
222221
from . import ImageFile, ImagePalette
222+
from ._typing import NumpyArray, StrOrBytesPath, TypeGuard
223223
ID: list[str] = []
224224
OPEN: dict[
225225
str,
@@ -2203,15 +2203,15 @@ def _get_safe_box(self, size, resample, box):
22032203

22042204
def resize(
22052205
self,
2206-
size: tuple[int, int],
2206+
size: tuple[int, int] | list[int] | NumpyArray,
22072207
resample: int | None = None,
22082208
box: tuple[float, float, float, float] | None = None,
22092209
reducing_gap: float | None = None,
22102210
) -> Image:
22112211
"""
22122212
Returns a resized copy of this image.
22132213
2214-
:param size: The requested size in pixels, as a 2-tuple:
2214+
:param size: The requested size in pixels, as a tuple or array:
22152215
(width, height).
22162216
:param resample: An optional resampling filter. This can be
22172217
one of :py:data:`Resampling.NEAREST`, :py:data:`Resampling.BOX`,
@@ -2276,6 +2276,7 @@ def resize(
22762276
if box is None:
22772277
box = (0, 0) + self.size
22782278

2279+
size = tuple(size)
22792280
if self.size == size and box == (0, 0) + self.size:
22802281
return self.copy()
22812282

0 commit comments

Comments
 (0)