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

Added in_place argument to ImageOps.exif_transpose() #7092

Merged
merged 7 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use snake case
  • Loading branch information
radarhere committed Jun 14, 2023
commit 7d97fa8b86a9f61069579fbedb2cc09fb437b12f
4 changes: 2 additions & 2 deletions Tests/test_imageops.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,13 @@ def check(orientation_im):
assert 0x0112 not in transposed_im.getexif()


def test_exif_transpose_inplace():
def test_exif_transpose_in_place():
with Image.open("Tests/images/orientation_rectangle.jpg") as im:
assert im.size == (2, 1)
assert im.getexif()[0x0112] == 8
hugovk marked this conversation as resolved.
Show resolved Hide resolved
expected = im.rotate(90, expand=True)

ImageOps.exif_transpose(im, inPlace=True)
ImageOps.exif_transpose(im, in_place=True)
assert im.size == (1, 2)
assert 0x0112 not in im.getexif()
assert_image_equal(im, expected)
Expand Down
12 changes: 6 additions & 6 deletions src/PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,13 +576,13 @@ def solarize(image, threshold=128):
return _lut(image, lut)


def exif_transpose(image, *, inPlace=False):
def exif_transpose(image, *, in_place=False):
"""
If an image has an EXIF Orientation tag, other than 1, transpose the image
accordingly, and remove the orientation data.

:param image: The image to transpose.
:param inPlace: Boolean. Keyword-only argument.
:param in_place: Boolean. Keyword-only argument.
If ``True``, the original image is modified in-place, and ``None`` is returned.
If ``False`` (default), a new :py:class:`~PIL.Image.Image` object is returned
with the transposition applied. If there is no transposition, a copy of the
Expand All @@ -601,11 +601,11 @@ def exif_transpose(image, *, inPlace=False):
}.get(orientation)
if method is not None:
transposed_image = image.transpose(method)
if inPlace:
if in_place:
image.im = transposed_image.im
image.pyaccess = None
image._size = transposed_image._size
exif_image = image if inPlace else transposed_image
exif_image = image if in_place else transposed_image

exif = exif_image.getexif()
if ExifTags.Base.Orientation in exif:
Expand All @@ -622,7 +622,7 @@ def exif_transpose(image, *, inPlace=False):
exif_image.info["XML:com.adobe.xmp"] = re.sub(
pattern, "", exif_image.info["XML:com.adobe.xmp"]
)
if not inPlace:
if not in_place:
return transposed_image
elif not inPlace:
elif not in_place:
return image.copy()