mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Add a scale function to expand or contract a PIL image by a factor factor
passed in argument.
This commit is contained in:
parent
2023c7cea1
commit
ea00713099
20
PIL/Image.py
20
PIL/Image.py
|
@ -1547,6 +1547,26 @@ class Image(object):
|
||||||
|
|
||||||
return self._new(self.im.resize(size, resample))
|
return self._new(self.im.resize(size, resample))
|
||||||
|
|
||||||
|
def scale(self, factor, resample = NEAREST):
|
||||||
|
"""
|
||||||
|
Returns a rescaled image by a specific factor given in parameter.
|
||||||
|
A factor greater than 1 expands the image, between 0 and 1 contracts the
|
||||||
|
image.
|
||||||
|
|
||||||
|
:param factor: The expansion factor, as a float.
|
||||||
|
:param resample: An optional resampling filter. Same values possible as
|
||||||
|
in the PIL.Image.resize function.
|
||||||
|
:returns: An :py:class:`~PIL.Image.Image` object.
|
||||||
|
"""
|
||||||
|
if factor == 1:
|
||||||
|
return self._new(self.im)
|
||||||
|
elif factor <= 0:
|
||||||
|
raise ValueError("the factor must be greater than 0")
|
||||||
|
else:
|
||||||
|
size = (int(round(factor * self.width)),
|
||||||
|
int(round(factor * self.height)))
|
||||||
|
return self.resize(size, resample)
|
||||||
|
|
||||||
def rotate(self, angle, resample=NEAREST, expand=0):
|
def rotate(self, angle, resample=NEAREST, expand=0):
|
||||||
"""
|
"""
|
||||||
Returns a rotated copy of this image. This method returns a
|
Returns a rotated copy of this image. This method returns a
|
||||||
|
|
Loading…
Reference in New Issue
Block a user