Skip to content

Commit 6043f1c

Browse files
committed
Add transposition support to PillowStep
Fixes bug where images are rotated incorrectly
1 parent 20e06c4 commit 6043f1c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/anchovy/images.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ class PillowStep(Step):
102102
"""
103103
A simple Pillow step which can convert and/or thumbnail images.
104104
"""
105-
def __init__(self, thumbnail: tuple[int, int] | None = None):
105+
def __init__(self, thumbnail: tuple[int, int] | None = None, transpose: bool = True):
106106
self.thumbnail = thumbnail
107+
self.transpose = transpose
107108

108109
@classmethod
109110
def get_dependencies(cls):
@@ -112,13 +113,15 @@ def get_dependencies(cls):
112113
}
113114

114115
def __call__(self, path: Path, output_paths: list[Path]):
115-
from PIL import Image
116+
from PIL import Image, ImageOps
116117

117118
groups = {}
118119
for target_path in output_paths:
119120
groups.setdefault(target_path.suffix, []).append(target_path)
120121

121122
with Image.open(path) as img:
123+
if self.transpose:
124+
ImageOps.exif_transpose(img, in_place=True)
122125
if self.thumbnail:
123126
img.thumbnail(self.thumbnail)
124127

0 commit comments

Comments
 (0)