mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge pull request #8201 from radarhere/resize
This commit is contained in:
commit
6cef133554
|
@ -285,14 +285,14 @@ class TestReducingGapResize:
|
|||
|
||||
class TestImageResize:
|
||||
def test_resize(self) -> None:
|
||||
def resize(mode: str, size: tuple[int, int]) -> None:
|
||||
def resize(mode: str, size: tuple[int, int] | list[int]) -> None:
|
||||
out = hopper(mode).resize(size)
|
||||
assert out.mode == mode
|
||||
assert out.size == size
|
||||
assert out.size == tuple(size)
|
||||
|
||||
for mode in "1", "P", "L", "RGB", "I", "F":
|
||||
resize(mode, (112, 103))
|
||||
resize(mode, (188, 214))
|
||||
resize(mode, [188, 214])
|
||||
|
||||
# Test unknown resampling filter
|
||||
with hopper() as im:
|
||||
|
|
|
@ -198,6 +198,15 @@ def test_putdata() -> None:
|
|||
assert len(im.getdata()) == len(arr)
|
||||
|
||||
|
||||
def test_resize() -> None:
|
||||
im = hopper()
|
||||
size = (64, 64)
|
||||
|
||||
im_resized = im.resize(numpy.array(size))
|
||||
|
||||
assert im_resized.size == size
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"dtype",
|
||||
(
|
||||
|
|
|
@ -63,7 +63,6 @@ from . import (
|
|||
)
|
||||
from ._binary import i32le, o32be, o32le
|
||||
from ._deprecate import deprecate
|
||||
from ._typing import StrOrBytesPath, TypeGuard
|
||||
from ._util import DeferredError, is_path
|
||||
|
||||
ElementTree: ModuleType | None
|
||||
|
@ -220,6 +219,7 @@ if hasattr(core, "DEFAULT_STRATEGY"):
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from . import ImageFile, ImagePalette
|
||||
from ._typing import NumpyArray, StrOrBytesPath, TypeGuard
|
||||
ID: list[str] = []
|
||||
OPEN: dict[
|
||||
str,
|
||||
|
@ -2203,7 +2203,7 @@ class Image:
|
|||
|
||||
def resize(
|
||||
self,
|
||||
size: tuple[int, int],
|
||||
size: tuple[int, int] | list[int] | NumpyArray,
|
||||
resample: int | None = None,
|
||||
box: tuple[float, float, float, float] | None = None,
|
||||
reducing_gap: float | None = None,
|
||||
|
@ -2211,7 +2211,7 @@ class Image:
|
|||
"""
|
||||
Returns a resized copy of this image.
|
||||
|
||||
:param size: The requested size in pixels, as a 2-tuple:
|
||||
:param size: The requested size in pixels, as a tuple or array:
|
||||
(width, height).
|
||||
:param resample: An optional resampling filter. This can be
|
||||
one of :py:data:`Resampling.NEAREST`, :py:data:`Resampling.BOX`,
|
||||
|
@ -2276,6 +2276,7 @@ class Image:
|
|||
if box is None:
|
||||
box = (0, 0) + self.size
|
||||
|
||||
size = tuple(size)
|
||||
if self.size == size and box == (0, 0) + self.size:
|
||||
return self.copy()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user