mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-23 23:30:34 +03:00
Various fixes
This commit is contained in:
parent
1aa3886ed7
commit
d44e9fccb1
|
@ -483,7 +483,7 @@ def _getscaleoffset(expr):
|
||||||
|
|
||||||
|
|
||||||
class _GetDataTransform(Protocol):
|
class _GetDataTransform(Protocol):
|
||||||
def getdata(self) -> tuple[Transform, Sequence[int]]: ...
|
def getdata(self) -> tuple[Transform, Sequence[float]]: ...
|
||||||
|
|
||||||
|
|
||||||
class Image:
|
class Image:
|
||||||
|
@ -2134,7 +2134,7 @@ class Image:
|
||||||
def resize(
|
def resize(
|
||||||
self,
|
self,
|
||||||
size: tuple[int, int],
|
size: tuple[int, int],
|
||||||
resample: Resampling | 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,
|
||||||
) -> Image:
|
) -> Image:
|
||||||
|
@ -2202,13 +2202,13 @@ 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)
|
||||||
|
|
||||||
size = tuple(size)
|
size = cast(tuple[int, int], tuple(size))
|
||||||
|
|
||||||
self.load()
|
self.load()
|
||||||
if box is None:
|
if box is None:
|
||||||
box = (0, 0) + self.size
|
box = (0, 0) + self.size
|
||||||
else:
|
else:
|
||||||
box = tuple(box)
|
box = cast(tuple[float, float, float, float], tuple(box))
|
||||||
|
|
||||||
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()
|
||||||
|
@ -2266,7 +2266,7 @@ class Image:
|
||||||
if box is None:
|
if box is None:
|
||||||
box = (0, 0) + self.size
|
box = (0, 0) + self.size
|
||||||
else:
|
else:
|
||||||
box = tuple(box)
|
box = cast(tuple[int, int, int, int], tuple(box))
|
||||||
|
|
||||||
if factor == (1, 1) and box == (0, 0) + self.size:
|
if factor == (1, 1) and box == (0, 0) + self.size:
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
@ -2283,7 +2283,7 @@ class Image:
|
||||||
def rotate(
|
def rotate(
|
||||||
self,
|
self,
|
||||||
angle: float,
|
angle: float,
|
||||||
resample: Resampling = Resampling.NEAREST,
|
resample: int = Resampling.NEAREST,
|
||||||
expand: bool = False,
|
expand: bool = False,
|
||||||
center: tuple[int, int] | None = None,
|
center: tuple[int, int] | None = None,
|
||||||
translate: tuple[int, int] | None = None,
|
translate: tuple[int, int] | None = None,
|
||||||
|
@ -2598,7 +2598,7 @@ class Image:
|
||||||
def thumbnail(
|
def thumbnail(
|
||||||
self,
|
self,
|
||||||
size: tuple[int, int],
|
size: tuple[int, int],
|
||||||
resample: Resampling = Resampling.BICUBIC,
|
resample: int = Resampling.BICUBIC,
|
||||||
reducing_gap: float = 2.0,
|
reducing_gap: float = 2.0,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -2661,20 +2661,22 @@ class Image:
|
||||||
|
|
||||||
box = None
|
box = None
|
||||||
if reducing_gap is not None:
|
if reducing_gap is not None:
|
||||||
size = preserve_aspect_ratio()
|
preserved_size = preserve_aspect_ratio()
|
||||||
if size is None:
|
if preserved_size is None:
|
||||||
return
|
return
|
||||||
|
size = preserved_size
|
||||||
|
|
||||||
res = self.draft(None, (size[0] * reducing_gap, size[1] * reducing_gap))
|
res = self.draft(None, (size[0] * reducing_gap, size[1] * reducing_gap)) # type: ignore[arg-type]
|
||||||
if res is not None:
|
if res is not None:
|
||||||
box = res[1]
|
box = res[1]
|
||||||
if box is None:
|
if box is None:
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
# load() may have changed the size of the image
|
# load() may have changed the size of the image
|
||||||
size = preserve_aspect_ratio()
|
preserved_size = preserve_aspect_ratio()
|
||||||
if size is None:
|
if preserved_size is None:
|
||||||
return
|
return
|
||||||
|
size = preserved_size
|
||||||
|
|
||||||
if self.size != size:
|
if self.size != size:
|
||||||
im = self.resize(size, resample, box=box, reducing_gap=reducing_gap)
|
im = self.resize(size, resample, box=box, reducing_gap=reducing_gap)
|
||||||
|
@ -2693,8 +2695,8 @@ class Image:
|
||||||
self,
|
self,
|
||||||
size: tuple[int, int],
|
size: tuple[int, int],
|
||||||
method: Transform | ImageTransformHandler,
|
method: Transform | ImageTransformHandler,
|
||||||
data: Sequence[int],
|
data: Sequence[float],
|
||||||
resample: Resampling = Resampling.NEAREST,
|
resample: int = Resampling.NEAREST,
|
||||||
fill: int = 1,
|
fill: int = 1,
|
||||||
fillcolor: float | tuple[float, ...] | str | None = None,
|
fillcolor: float | tuple[float, ...] | str | None = None,
|
||||||
) -> Image: ...
|
) -> Image: ...
|
||||||
|
@ -2704,7 +2706,17 @@ class Image:
|
||||||
size: tuple[int, int],
|
size: tuple[int, int],
|
||||||
method: _GetDataTransform,
|
method: _GetDataTransform,
|
||||||
data: None = None,
|
data: None = None,
|
||||||
resample: Resampling = Resampling.NEAREST,
|
resample: int = Resampling.NEAREST,
|
||||||
|
fill: int = 1,
|
||||||
|
fillcolor: float | tuple[float, ...] | str | None = None,
|
||||||
|
) -> Image: ...
|
||||||
|
@overload
|
||||||
|
def transform(
|
||||||
|
self,
|
||||||
|
size: tuple[int, int],
|
||||||
|
method: Transform | ImageTransformHandler | _GetDataTransform,
|
||||||
|
data: Sequence[float] | None = None,
|
||||||
|
resample: int = Resampling.NEAREST,
|
||||||
fill: int = 1,
|
fill: int = 1,
|
||||||
fillcolor: float | tuple[float, ...] | str | None = None,
|
fillcolor: float | tuple[float, ...] | str | None = None,
|
||||||
) -> Image: ...
|
) -> Image: ...
|
||||||
|
@ -2712,8 +2724,8 @@ class Image:
|
||||||
self,
|
self,
|
||||||
size: tuple[int, int],
|
size: tuple[int, int],
|
||||||
method: Transform | ImageTransformHandler | _GetDataTransform,
|
method: Transform | ImageTransformHandler | _GetDataTransform,
|
||||||
data: Sequence[int] | None = None,
|
data: Sequence[float] | None = None,
|
||||||
resample: Resampling = Resampling.NEAREST,
|
resample: int = Resampling.NEAREST,
|
||||||
fill: int = 1,
|
fill: int = 1,
|
||||||
fillcolor: float | tuple[float, ...] | str | None = None,
|
fillcolor: float | tuple[float, ...] | str | None = None,
|
||||||
) -> Image:
|
) -> Image:
|
||||||
|
|
|
@ -40,7 +40,7 @@ from ._typing import StrOrBytesPath
|
||||||
from ._util import is_directory, is_path
|
from ._util import is_directory, is_path
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from _imagingft import Font
|
from ._imagingft import Font
|
||||||
|
|
||||||
|
|
||||||
class Layout(IntEnum):
|
class Layout(IntEnum):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user