Do not create new image when exif_transpose() is used in place by radarhere · Pull Request #8555 · python-pillow/Pillow
im.transpose() loads the image, calls the core transpose() method and returns a new image instance.
| def transpose(self, method: Transpose) -> Image: | |
| """ | |
| Transpose image (flip or rotate in 90 degree steps) | |
| :param method: One of :py:data:`Transpose.FLIP_LEFT_RIGHT`, | |
| :py:data:`Transpose.FLIP_TOP_BOTTOM`, :py:data:`Transpose.ROTATE_90`, | |
| :py:data:`Transpose.ROTATE_180`, :py:data:`Transpose.ROTATE_270`, | |
| :py:data:`Transpose.TRANSPOSE` or :py:data:`Transpose.TRANSVERSE`. | |
| :returns: Returns a flipped or rotated copy of this image. | |
| """ | |
| self.load() | |
| return self._new(self.im.transpose(method)) |
When im.transpose() is called from ImageOps.exif_transpose(), if it is in_place, then the image is already loaded, and the new image instance is quickly abandoned.
| transposed_image = image.transpose(method) | |
| if in_place: | |
| image.im = transposed_image.im | |
| image._size = transposed_image._size | |
| exif_image = image if in_place else transposed_image |
So this can be simplified to just calling the core transpose() method directly.