-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
21 lines (17 loc) · 767 Bytes
/
test.py
File metadata and controls
21 lines (17 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from wand.image import Image
def fix_image_orientation(image_path, output_path):
# Open the image using Wand (ImageMagick)
with Image(filename=image_path) as img:
# Check if the image has EXIF data (orientation)
exif = img.metadata.get('exif:Orientation') # Check EXIF orientation
# Rotate based on EXIF orientation
if exif == '3':
img.rotate(degree=180)
elif exif == '6':
img.rotate(degree=270) # Rotate 270 degrees clockwise
elif exif == '8':
img.rotate(degree=90) # Rotate 90 degrees clockwise
# Save the image with the correct orientation
img.save(filename=output_path)
# Example usage
fix_image_orientation("input_image.jpg", "output_image.jpg")