Move the scale function from Image to ImageOps

This commit is contained in:
Marco De Donno 2016-07-05 01:32:06 +02:00
parent ea00713099
commit c0eb87cac3
2 changed files with 21 additions and 20 deletions

View File

@ -1547,26 +1547,6 @@ class Image(object):
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):
"""
Returns a rotated copy of this image. This method returns a

View File

@ -178,6 +178,27 @@ def crop(image, border=0):
)
def scale(self, factor, resample=Image.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 deform(image, deformer, resample=Image.BILINEAR):
"""
Deform the image.