mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-03 19:33:07 +03:00
Add scale param to resize
This commit is contained in:
parent
eeb3d04843
commit
f6df61dc37
|
@ -2219,6 +2219,7 @@ class Image:
|
||||||
def resize(
|
def resize(
|
||||||
self,
|
self,
|
||||||
size: tuple[int, int] | list[int] | NumpyArray,
|
size: tuple[int, int] | list[int] | NumpyArray,
|
||||||
|
scale: float | None = None,
|
||||||
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,
|
||||||
|
@ -2228,6 +2229,9 @@ class Image:
|
||||||
|
|
||||||
:param size: The requested size in pixels, as a tuple or array:
|
:param size: The requested size in pixels, as a tuple or array:
|
||||||
(width, height).
|
(width, height).
|
||||||
|
:param scale: An optional scale factor to upsample/downsample the image:
|
||||||
|
(e.g. 0.5 means that an image (width, height) will be
|
||||||
|
resized to (width/2, height/2)). If provided overwrite size.
|
||||||
: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`,
|
||||||
:py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`,
|
:py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`,
|
||||||
|
@ -2287,6 +2291,12 @@ class Image:
|
||||||
msg = "reducing_gap must be 1.0 or greater"
|
msg = "reducing_gap must be 1.0 or greater"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
|
if scale:
|
||||||
|
size = (
|
||||||
|
int(self.width * scale),
|
||||||
|
int(self.height * scale)
|
||||||
|
)
|
||||||
|
|
||||||
self.load()
|
self.load()
|
||||||
if box is None:
|
if box is None:
|
||||||
box = (0, 0) + self.size
|
box = (0, 0) + self.size
|
||||||
|
|
Loading…
Reference in New Issue
Block a user