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