Skip to content

Commit

Permalink
Merge pull request #8657 from cdce8p/overload-exif_transpose
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Jan 3, 2025
2 parents 48712f2 + d12e78b commit 9ae8cb8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 0 additions & 1 deletion Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ def test_empty_exif_gps(self) -> None:
assert exif.get_ifd(0x8825) == {}

transposed = ImageOps.exif_transpose(im)
assert transposed is not None
exif = transposed.getexif()
assert exif.get_ifd(0x8825) == {}

Expand Down
6 changes: 0 additions & 6 deletions Tests/test_imageops.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ def check(orientation_im: Image.Image) -> None:
else:
original_exif = im.info["exif"]
transposed_im = ImageOps.exif_transpose(im)
assert transposed_im is not None
assert_image_similar(base_im, transposed_im, 17)
if orientation_im is base_im:
assert "exif" not in im.info
Expand All @@ -417,7 +416,6 @@ def check(orientation_im: Image.Image) -> None:

# Repeat the operation to test that it does not keep transposing
transposed_im2 = ImageOps.exif_transpose(transposed_im)
assert transposed_im2 is not None
assert_image_equal(transposed_im2, transposed_im)

check(base_im)
Expand All @@ -433,7 +431,6 @@ def check(orientation_im: Image.Image) -> None:
assert im.getexif()[0x0112] == 3

transposed_im = ImageOps.exif_transpose(im)
assert transposed_im is not None
assert 0x0112 not in transposed_im.getexif()

transposed_im._reload_exif()
Expand All @@ -446,14 +443,12 @@ def check(orientation_im: Image.Image) -> None:
assert im.getexif()[0x0112] == 3

transposed_im = ImageOps.exif_transpose(im)
assert transposed_im is not None
assert 0x0112 not in transposed_im.getexif()

# Orientation set directly on Image.Exif
im = hopper()
im.getexif()[0x0112] = 3
transposed_im = ImageOps.exif_transpose(im)
assert transposed_im is not None
assert 0x0112 not in transposed_im.getexif()


Expand All @@ -464,7 +459,6 @@ def test_exif_transpose_xml_without_xmp() -> None:

del im.info["xmp"]
transposed_im = ImageOps.exif_transpose(im)
assert transposed_im is not None
assert 0x0112 not in transposed_im.getexif()


Expand Down
12 changes: 11 additions & 1 deletion src/PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import operator
import re
from collections.abc import Sequence
from typing import Protocol, cast
from typing import Literal, Protocol, cast, overload

from . import ExifTags, Image, ImagePalette

Expand Down Expand Up @@ -673,6 +673,16 @@ def solarize(image: Image.Image, threshold: int = 128) -> Image.Image:
return _lut(image, lut)


@overload
def exif_transpose(image: Image.Image, *, in_place: Literal[True]) -> None: ...


@overload
def exif_transpose(
image: Image.Image, *, in_place: Literal[False] = False
) -> Image.Image: ...


def exif_transpose(image: Image.Image, *, in_place: bool = False) -> Image.Image | None:
"""
If an image has an EXIF Orientation tag, other than 1, transpose the image
Expand Down

0 comments on commit 9ae8cb8

Please sign in to comment.