use one self.transform for rotation

This commit is contained in:
homm 2016-06-02 11:36:41 +03:00
parent 7687ce829e
commit 709078efd1

View File

@ -30,6 +30,7 @@ from PIL import VERSION, PILLOW_VERSION, _plugins
import logging import logging
import warnings import warnings
import math
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -1581,8 +1582,7 @@ class Image(object):
if angle == 270 and expand: if angle == 270 and expand:
return self.transpose(ROTATE_270) return self.transpose(ROTATE_270)
if expand:
import math
angle = - math.radians(angle) angle = - math.radians(angle)
matrix = [ matrix = [
round(math.cos(angle), 15), round(math.sin(angle), 15), 0.0, round(math.cos(angle), 15), round(math.sin(angle), 15), 0.0,
@ -1593,8 +1593,9 @@ class Image(object):
(a, b, c, d, e, f) = matrix (a, b, c, d, e, f) = matrix
return a*x + b*y + c, d*x + e*y + f return a*x + b*y + c, d*x + e*y + f
# calculate output size
w, h = self.size w, h = self.size
if expand:
# calculate output size
xx = [] xx = []
yy = [] yy = []
for x, y in ((0, 0), (w, 0), (w, h), (0, h)): for x, y in ((0, 0), (w, 0), (w, h), (0, h)):
@ -1611,16 +1612,6 @@ class Image(object):
return self.transform((w, h), AFFINE, matrix, resample) return self.transform((w, h), AFFINE, matrix, resample)
if resample not in (NEAREST, BILINEAR, BICUBIC):
raise ValueError("unknown resampling filter")
self.load()
if self.mode in ("1", "P"):
resample = NEAREST
return self._new(self.im.rotate(angle, resample, expand))
def save(self, fp, format=None, **params): def save(self, fp, format=None, **params):
""" """
Saves this image under the given filename. If no format is Saves this image under the given filename. If no format is