Skip to content

Conversation

@radarhere
Copy link
Member

im.transpose() loads the image, calls the core transpose() method and returns a new image instance.

Pillow/src/PIL/Image.py

Lines 2982 to 2994 in 5bff2f3

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.

Pillow/src/PIL/ImageOps.py

Lines 701 to 705 in 5bff2f3

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.

@hugovk hugovk merged commit 86d396a into python-pillow:main Dec 27, 2024
48 checks passed
@radarhere radarhere deleted the exif branch December 27, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants