Skip to content

Commit f074ef6

Browse files
[pillow] add new PIL.Image enums (#8419)
Co-authored-by: Shantanu <[email protected]>
1 parent e48c176 commit f074ef6

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

stubs/Pillow/PIL/Image.pyi

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from _typeshed import Self, SupportsRead, SupportsWrite
22
from collections.abc import Callable, Iterable, Iterator, MutableMapping, Sequence
3+
from enum import IntEnum
34
from pathlib import Path
45
from typing import Any, ClassVar, Protocol, SupportsBytes, Union
56
from typing_extensions import Literal, TypeAlias
@@ -78,6 +79,46 @@ MAXCOVERAGE: Literal[1]
7879
FASTOCTREE: Literal[2]
7980
LIBIMAGEQUANT: Literal[3]
8081

82+
class Transpose(IntEnum):
83+
FLIP_LEFT_RIGHT: Literal[0]
84+
FLIP_TOP_BOTTOM: Literal[1]
85+
ROTATE_90: Literal[2]
86+
ROTATE_180: Literal[3]
87+
ROTATE_270: Literal[4]
88+
TRANSPOSE: Literal[5]
89+
TRANSVERSE: Literal[6]
90+
91+
class Transform(IntEnum):
92+
AFFINE: Literal[0]
93+
EXTENT: Literal[1]
94+
PERSPECTIVE: Literal[2]
95+
QUAD: Literal[3]
96+
MESH: Literal[4]
97+
98+
class Resampling(IntEnum):
99+
NEAREST: Literal[0]
100+
LANCZOS: Literal[1]
101+
BILINEAR: Literal[2]
102+
BICUBIC: Literal[3]
103+
BOX: Literal[4]
104+
HAMMING: Literal[5]
105+
106+
class Dither(IntEnum):
107+
NONE: Literal[0]
108+
ORDERED: Literal[1]
109+
RASTERIZE: Literal[2]
110+
FLOYDSTEINBERG: Literal[3]
111+
112+
class Palette(IntEnum):
113+
WEB: Literal[0]
114+
ADAPTIVE: Literal[1]
115+
116+
class Quantize(IntEnum):
117+
MEDIANCUT: Literal[0]
118+
MAXCOVERAGE: Literal[1]
119+
FASTOCTREE: Literal[2]
120+
LIBIMAGEQUANT: Literal[3]
121+
81122
ID: list[str]
82123
OPEN: dict[str, Any]
83124
MIME: dict[str, str]
@@ -137,7 +178,7 @@ class Image:
137178
mode: _Mode | None = ...,
138179
matrix: _ConversionMatrix | None = ...,
139180
dither: int | None = ...,
140-
palette: Literal[0, 1] = ...,
181+
palette: Literal[Palette.WEB] = ...,
141182
colors: int = ...,
142183
) -> Image: ...
143184
def quantize(
@@ -176,15 +217,15 @@ class Image:
176217
def resize(
177218
self,
178219
size: tuple[int, int],
179-
resample: _Resample | None = ...,
220+
resample: Resampling | _Resample | None = ...,
180221
box: tuple[float, float, float, float] | None = ...,
181222
reducing_gap: float | None = ...,
182223
) -> Image: ...
183224
def reduce(self, factor: int | tuple[int, int] | list[int], box: _Box | None = ...) -> Image: ...
184225
def rotate(
185226
self,
186227
angle: float,
187-
resample: _Resample = ...,
228+
resample: Resampling | _Resample = ...,
188229
expand: bool = ...,
189230
center: tuple[float, float] | None = ...,
190231
translate: tuple[float, float] | None = ...,
@@ -204,17 +245,17 @@ class Image:
204245
def split(self) -> tuple[Image, ...]: ...
205246
def getchannel(self, channel: int | str) -> Image: ...
206247
def tell(self) -> int: ...
207-
def thumbnail(self, size: tuple[int, int], resample: _Resample = ..., reducing_gap: float = ...) -> None: ...
248+
def thumbnail(self, size: tuple[int, int], resample: Resampling | _Resample = ..., reducing_gap: float = ...) -> None: ...
208249
def transform(
209250
self,
210251
size: _Size,
211-
method: Literal[0, 1, 2, 3, 4],
252+
method: Transform | Literal[0, 1, 2, 3, 4],
212253
data=...,
213-
resample: _Resample = ...,
254+
resample: Resampling | _Resample = ...,
214255
fill: int = ...,
215256
fillcolor: _Color | int | None = ...,
216257
) -> Image: ...
217-
def transpose(self, method: Literal[0, 1, 2, 3, 4, 5, 6]) -> Image: ...
258+
def transpose(self, method: Transpose | Literal[0, 1, 2, 3, 4, 5, 6]) -> Image: ...
218259
def effect_spread(self, distance: int) -> Image: ...
219260
def toqimage(self): ...
220261
def toqpixmap(self): ...

stubs/Pillow/PIL/ImageOps.pyi

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from collections.abc import Iterable
22
from typing import Any, Protocol, Union
33
from typing_extensions import TypeAlias
44

5-
from .Image import Image, _Resample, _Size
5+
from .Image import Image, Resampling, _Resample, _Size
66
from .ImageColor import _Ink
77

88
_Border: TypeAlias = Union[int, tuple[int, int], tuple[int, int, int, int]]
@@ -22,16 +22,18 @@ def colorize(
2222
whitepoint: int = ...,
2323
midpoint: int = ...,
2424
) -> Image: ...
25-
def contain(image: Image, size: _Size, method: _Resample = ...) -> Image: ...
25+
def contain(image: Image, size: _Size, method: Resampling | _Resample = ...) -> Image: ...
2626
def pad(
27-
image: Image, size: _Size, method: _Resample = ..., color: Any | None = ..., centering: Iterable[float] = ...
27+
image: Image, size: _Size, method: Resampling | _Resample = ..., color: Any | None = ..., centering: Iterable[float] = ...
2828
) -> Image: ...
2929
def crop(image: Image, border: _Border = ...) -> Image: ...
30-
def scale(image: Image, factor: float, resample: _Resample = ...) -> Image: ...
31-
def deform(image: Image, deformer: _Deformer, resample: _Resample = ...) -> Image: ...
30+
def scale(image: Image, factor: float, resample: Resampling | _Resample = ...) -> Image: ...
31+
def deform(image: Image, deformer: _Deformer, resample: Resampling | _Resample = ...) -> Image: ...
3232
def equalize(image: Image, mask: Any | None = ...) -> Image: ...
3333
def expand(image: Image, border: _Border = ..., fill: _Ink = ...) -> Image: ...
34-
def fit(image: Image, size: _Size, method: _Resample = ..., bleed: float = ..., centering: Iterable[float] = ...) -> Image: ...
34+
def fit(
35+
image: Image, size: _Size, method: Resampling | _Resample = ..., bleed: float = ..., centering: Iterable[float] = ...
36+
) -> Image: ...
3537
def flip(image: Image) -> Image: ...
3638
def grayscale(image: Image) -> Image: ...
3739
def invert(image: Image) -> Image: ...

0 commit comments

Comments
 (0)