Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not create new image when exif_transpose() is used in place #8555

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

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.

1 participant