How to preserve Image Quality when rotating with PIL
python, python-imaging-library
Solution
rotated_small = photo_small.rotate(angle, resample=Image.BICUBIC, expand=True)
This tells it to use the highest quality interpolation algorithm that it has available, and to expand the image to encompass the full rotated size instead of cropping. The documentation does not say what color the background will be filled with.
Problem
Basically I'm trying to be able to rotate images via user interface, however I've noticed that the image quality severely decreases upon each rotation. Does anyone know how to fix that? Also when the image is rotated it crops off parts of the image each time. here are some pictures of before and after: https://i.stack.imgur.com/M5WVJ.jpg And here's the code: ``` def onRotate(self): tanTheta = float(hh)/float(ww) theta = math.atan(tanTheta) * 57.2957795 # convert to degrees if theta > 0: angle = (90 - theta) * -1 clockwise = True elif theta < 0: angle = (270 - theta) * -1 clockwise = False else: tkMessageBox('Angle not okay', 'Try again!') rotated_small = photo_small.rotate(angle) rotated_small.save('small_rotate.jpg') self.load_imgfile('small_rotate.jpg') ```