Skip to content

Commit 1b171a4

Browse files
committed
Apply EXIF orientation before resizing in optimize_image.py
Add ImageOps.exif_transpose() call after opening the image so that JPEGs with EXIF Orientation metadata are correctly rotated/flipped before mode conversion and resizing. Without this, output WebPs could appear rotated compared to the original. Fixes review feedback on PR #106.
1 parent 947b846 commit 1b171a4

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

scripts/optimize_image.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from pathlib import Path
2424

2525
try:
26-
from PIL import Image
26+
from PIL import Image, ImageOps
2727
except ImportError:
2828
print(
2929
"Error: Pillow is not installed.\n"
@@ -50,6 +50,9 @@ def optimize_image(input_path: Path, *, quality: int, max_width: int) -> Path |
5050
print(f" Error opening {input_path.name}: {e}", file=sys.stderr)
5151
return None
5252

53+
# Apply EXIF orientation so JPEGs rotated via metadata are correctly oriented
54+
img = ImageOps.exif_transpose(img)
55+
5356
# Convert palette/RGBA images appropriately for WebP
5457
if img.mode in ("P", "PA"):
5558
img = img.convert("RGBA")

0 commit comments

Comments
 (0)