mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-26 07:04:45 +03:00
Typing: Image.transform
This commit is contained in:
parent
404d6f31c7
commit
a5c66e456b
|
@ -741,7 +741,7 @@ class Image(object):
|
||||||
|
|
||||||
:param encoder_name: What encoder to use. The default is to
|
:param encoder_name: What encoder to use. The default is to
|
||||||
use the standard "raw" encoder.
|
use the standard "raw" encoder.
|
||||||
:param *args: Extra arguments to the encoder. May be one tuple,
|
:param *args: Extra arguments to the encoder. May be one tuple,
|
||||||
or individual arguments
|
or individual arguments
|
||||||
:rtype: A bytes object.
|
:rtype: A bytes object.
|
||||||
"""
|
"""
|
||||||
|
@ -2002,7 +2002,7 @@ class Image(object):
|
||||||
open_fp = True
|
open_fp = True
|
||||||
else:
|
else:
|
||||||
_fp = fp # type: ignore
|
_fp = fp # type: ignore
|
||||||
|
|
||||||
if not filename and hasattr(_fp, "name") and isPath(_fp.name):
|
if not filename and hasattr(_fp, "name") and isPath(_fp.name):
|
||||||
# only set the name for metadata purposes
|
# only set the name for metadata purposes
|
||||||
filename = _fp.name
|
filename = _fp.name
|
||||||
|
@ -2202,7 +2202,7 @@ class Image(object):
|
||||||
# instead of bloating the method docs, add a separate chapter.
|
# instead of bloating the method docs, add a separate chapter.
|
||||||
def transform(self, size, method, data=None, resample=NEAREST,
|
def transform(self, size, method, data=None, resample=NEAREST,
|
||||||
fill=1, fillcolor=None):
|
fill=1, fillcolor=None):
|
||||||
# type: (Size, int, Optional[List[float]], int, int, Optional[Color]) -> Image
|
# type: (Size, int, Optional[Union[List[float], List[Tuple[LURD,LURD]]]], int, int, Optional[Color]) -> Image
|
||||||
"""
|
"""
|
||||||
Transforms this image. This method creates a new image with the
|
Transforms this image. This method creates a new image with the
|
||||||
given size, and the same mode as the original, and copies data
|
given size, and the same mode as the original, and copies data
|
||||||
|
@ -2227,7 +2227,7 @@ class Image(object):
|
||||||
in the output image.
|
in the output image.
|
||||||
:returns: An :py:class:`~PIL.Image.Image` object.
|
:returns: An :py:class:`~PIL.Image.Image` object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.mode == 'LA':
|
if self.mode == 'LA':
|
||||||
return self.convert('La').transform(
|
return self.convert('La').transform(
|
||||||
size, method, data, resample, fill).convert('LA')
|
size, method, data, resample, fill).convert('LA')
|
||||||
|
@ -2241,7 +2241,8 @@ class Image(object):
|
||||||
|
|
||||||
if hasattr(method, "getdata"):
|
if hasattr(method, "getdata"):
|
||||||
# compatibility w. old-style transform objects
|
# compatibility w. old-style transform objects
|
||||||
method, data = method.getdata()
|
# ignoring for typing, this is old compatibility
|
||||||
|
method, data = method.getdata() # type: ignore
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
raise ValueError("missing method data")
|
raise ValueError("missing method data")
|
||||||
|
@ -2249,11 +2250,15 @@ class Image(object):
|
||||||
im = new(self.mode, size, fillcolor)
|
im = new(self.mode, size, fillcolor)
|
||||||
if method == MESH:
|
if method == MESH:
|
||||||
# list of quads
|
# list of quads
|
||||||
for box, quad in data:
|
data_mesh = None # type: List[Tuple[LURD,LURD]]
|
||||||
|
data_mesh = data # type: ignore
|
||||||
|
for box, quad in data_mesh:
|
||||||
im.__transformer(box, self, QUAD, quad, resample,
|
im.__transformer(box, self, QUAD, quad, resample,
|
||||||
fillcolor is None)
|
fillcolor is None)
|
||||||
else:
|
else:
|
||||||
im.__transformer((0, 0)+size, self, method, data,
|
box_lurd = None # type: LURD
|
||||||
|
box_lurd = (0, 0)+size # type: ignore
|
||||||
|
im.__transformer(box_lurd, self, method, data,
|
||||||
resample, fillcolor is None)
|
resample, fillcolor is None)
|
||||||
|
|
||||||
return im
|
return im
|
||||||
|
|
Loading…
Reference in New Issue
Block a user